示例#1
0
文件: stmr.c 项目: wooorm/stmr.c
/* `step1ab()` gets rid of plurals, `-ed`, `-ing`.
 *
 * Such as:
 *
 *   caresses  ->  caress
 *   ponies    ->  poni
 *   ties      ->  ti
 *   caress    ->  caress
 *   cats      ->  cat
 *
 *   feed      ->  feed
 *   agreed    ->  agree
 *   disabled  ->  disable
 *
 *   matting   ->  mat
 *   mating    ->  mate
 *   meeting   ->  meet
 *   milling   ->  mill
 *   messing   ->  mess
 *
 *   meetings  ->  meet
 */
static void
step1ab() {
  int character;

  if (b[k] == 's') {
    if (ends("\04" "sses")) {
      k -= 2;
    } else if (ends("\03" "ies")) {
      setTo("\01" "i");
    } else if (b[k - 1] != 's') {
      k--;
    }
  }

  if (ends("\03" "eed")) {
    if (getMeasure() > 0) {
      k--;
    }
  } else if ((ends("\02" "ed") || ends("\03" "ing")) && vowelInStem()) {
    k = j;

    if (ends("\02" "at")) {
      setTo("\03" "ate");
    } else if (ends("\02" "bl")) {
      setTo("\03" "ble");
    } else if (ends("\02" "iz")) {
      setTo("\03" "ize");
    } else if (isDoubleConsonant(k)) {
      k--;

      character = b[k];

      if (character == 'l' || character == 's' || character == 'z') {
        k++;
      }
    } else if (getMeasure() == 1 && cvc(k)) {
      setTo("\01" "e");
    }
  }
}
bool StringPotentiometer::isFinished(String moveDirection, float targetMeasure) {
	float potUnits = getMeasure();
	bool targetReached = false;
	if (moveDirection == "UP  ") {
		if (targetMeasure <= potUnits) {
			targetReached = true;
		}
	} else {
		if (moveDirection == "DOWN") {
			if (targetMeasure >= potUnits) {
				targetReached = true;
			}
		}
	}
	return targetReached;
}
示例#3
0
 void writeMxMeasures( const mx::d::DocumentPartwisePtr& doc, const InstrumentListPtr& instrumentList )
 {
     auto scoreGrpsBeg = instrumentList->getScoreGroups().begin();
     auto scoreGrpsEnd = instrumentList->getScoreGroups().end();
     auto scoreGrpsItr = scoreGrpsBeg;
     for ( ; scoreGrpsItr != scoreGrpsEnd; ++scoreGrpsItr )
     {
         auto beg = (*scoreGrpsItr)->getInstruments().begin();
         auto end = (*scoreGrpsItr)->getInstruments().end();
         auto itr = beg;
         for (; itr != end; ++itr )
         {
             Int m = 1;
             for ( auto measure = (*itr)->getMeasuresBegin(); measure != (*itr)->getMeasuresEnd(); ++measure )
             {
                 auto currentInstrument = *itr;
                 auto mxmeasure = getMeasure( doc, currentInstrument->getID(), m );
                 fillMxMeasure( mxmeasure, *measure );
                 ++m;
             }
         }
     }
 }
示例#4
0
// tool function
void m_tree_t::leftR(node *n)
{
	node * tmpN;
	int tmpK;
	tmpN = n ->left;
	tmpK = n->key;

	n -> left = n -> right;
	n ->key = n ->right ->key;

	n ->right = n ->left ->right;
	n ->left ->right = n -> left -> left;
	n->left ->left = tmpN;
	n ->left ->key = tmpK;



	n ->left ->nodeIvl_l = n ->nodeIvl_l;
	n ->left ->nodeIvl_r = n ->key;

	getLeftMin(n ->left);
	getRightMax( n->left);
	getMeasure(n ->left);
}
示例#5
0
文件: stmr.c 项目: wooorm/stmr.c
/* `step4()` takes off -ant, -ence etc., in
 * context <c>vcvc<v>. */
static void
step4() {
  switch (b[k - 1]) {
    case 'a':
      if (ends("\02" "al")) {
        break;
      }

      return;
    case 'c':
      if (ends("\04" "ance")) {
        break;
      }

      if (ends("\04" "ence")) {
        break;
      }

      return;
    case 'e':
      if (ends("\02" "er")) {
        break;
      }

      return;
    case 'i':
      if (ends("\02" "ic")) {
        break;
      }

      return;
    case 'l':
      if (ends("\04" "able")) {
        break;
      }

      if (ends("\04" "ible")) {
        break;
      }

      return;
    case 'n':
      if (ends("\03" "ant")) {
        break;
      }

      if (ends("\05" "ement")) {
        break;
      }

      if (ends("\04" "ment")) {
        break;
      }

      if (ends("\03" "ent")) {
        break;
      }

      return;
    case 'o':
      if (ends("\03" "ion") && j >= k0 && (b[j] == 's' || b[j] == 't')) {
        break;
      }

      /* takes care of -ous */
      if (ends("\02" "ou")) {
        break;
      }

      return;
    case 's':
      if (ends("\03" "ism")) {
        break;
      }

      return;
    case 't':
      if (ends("\03" "ate")) {
        break;
      }

      if (ends("\03" "iti")) {
        break;
      }

      return;
    case 'u':
      if (ends("\03" "ous")) {
        break;
      }

      return;
    case 'v':
      if (ends("\03" "ive")) {
        break;
      }

      return;
    case 'z':
      if (ends("\03" "ize")) {
        break;
      }

      return;
    default:
      return;
  }

  if (getMeasure() > 1) {
    k = j;
  }
}
示例#6
0
文件: stmr.c 项目: wooorm/stmr.c
/* Set string. */
static void
replace(const char *value) {
  if (getMeasure() > 0) {
    setTo(value);
  }
}
示例#7
0
int Performance::getBar(void) {
   return getMeasure();
}
 Measure MeasureGroup_Impl::getMeasure(const DataPoint& dataPoint) const {
   OptionalInt index = dataPoint.problem().getVariableIndexByUUID(uuid());
   OS_ASSERT(index);
   return getMeasure(dataPoint.variableValues()[*index].toInt());
 }
示例#9
0
node * m_tree_t::removeNode(int index, int otherIndex)
{
	node * upper, *other;
	node *delNode = NULL;

	num --;
	node ** stack = new node*[num];
	int sindex = -1;

	if(root == NULL)
		return NULL;
	else if(root ->right == NULL)
	{
		if(index == root ->key)
		{
			node* pnode = root ->left;
			root ->left = NULL;
			root ->measure = 0;
			root ->ep_l.clear();
			root->ep_r.clear();
			return pnode;
		}
		else return NULL;
	}
	else
	{
		node * pnode = root;
		while(pnode ->right != NULL)
		{
			sindex ++;
			stack[sindex] = pnode;
			upper = pnode;
			if(index < pnode ->key)
			{
				pnode = upper ->left;
				other = upper ->right;
			}
			else
			{
				pnode = upper ->right;
				other = upper ->left;
			}//end of if-else
		}//end of while

		if(index == pnode ->key)
		{
			//printf("get the index %d , node %d\n",index, pnode ->left->key);
			if(pnode ->left ->time == 1)
			{
				upper ->key = other ->key;
				upper ->left = other -> left;
				upper ->right = other ->right;
				upper ->height = other ->height;
				delNode = pnode ->left;
				node * tmpN = pnode;
				returnNode(tmpN  ->left);
				returnNode(other);
				sindex --;

				upper ->left ->nodeIvl_l = upper->nodeIvl_l;
				if(upper ->right ==NULL)
				upper ->left ->nodeIvl_r = upper ->nodeIvl_r;
				else
				{
					upper ->left->nodeIvl_r = upper ->key;
					upper ->right ->nodeIvl_l = upper ->key;
					upper ->right ->nodeIvl_r = upper ->nodeIvl_r;
				}

				getLeftMin(upper);
				getRightMax(upper);
				getMeasure(upper);
			}
			else
			{
				pnode ->left -> time --;

				if(index < otherIndex)
				{

					pnode->left->ep_r.remove(otherIndex);
					pnode->left ->ep_l.remove(index);

				}
				else
				{

					pnode->left->ep_l.remove(otherIndex);
					pnode->left->ep_r.remove(index);

				}

				pnode ->ep_l = pnode->left ->ep_l;
				pnode ->ep_r = pnode ->left ->ep_r;

				if(pnode->left->ep_l.size() != 0)
				{
					pnode ->left ->leftmin = pnode->left->ep_l.min();
				}
				else
				
					pnode->left->leftmin = pnode->left->nodeIvl_l;
					

				if(pnode->left->ep_r.size() != 0)
				{
					pnode ->left ->rightmax = pnode ->left->ep_r.max();
				}
				else
					pnode->left ->rightmax = pnode ->left ->nodeIvl_r;

				getLeftMin(pnode);
				getRightMax(pnode);
				getMeasure(pnode);

				getLeftMin(upper);
				getRightMax(upper);
				getMeasure(upper);
			}//end of else to process the case multiple endpoint

		}
		else
			return NULL;

		int aindex = sindex;
		while(aindex > -1)
		{
			node * n = stack[aindex];
			aindex --;
			getLeftMin(n);
			getRightMax(n);
			getMeasure(n);
		}
	}//end of else

	//rebalance
	int finished = 0;
	while(sindex > -1 && !finished)
	{
		int tmpHeight, oldHeight;

		node * pnode = stack[sindex];
		sindex --;

		oldHeight = pnode ->height;
		if(pnode->left->height -  pnode ->right->height == 2)
		{
			if(pnode->left->left->height - pnode->right->height == 1)
			{
				rightR(pnode);
				pnode ->right ->height = pnode ->right ->left ->height +1;
				pnode ->height = pnode ->right ->height +1;
			}
			else
			{
				leftR(pnode ->left);
				rightR(pnode);
				tmpHeight = pnode ->left ->left ->height;
				pnode ->left ->height = tmpHeight +1;
				pnode ->right ->height = tmpHeight +1;
				pnode ->height = tmpHeight +2;
			}
		}
		else if(pnode->left->height - pnode->right->height == -2)
		{
			if(pnode ->right ->right ->height - pnode->left->height == 1)
			{
				leftR(pnode);
				pnode ->left ->height = pnode->left ->right ->height +1;
				pnode ->height = pnode ->left ->height +1;
			}
			else
			{
				rightR(pnode->right);
				leftR(pnode);
				tmpHeight = pnode ->right ->right ->height;

			}
		}
		else
		{
			if(pnode->left->height > pnode->right->height)
				pnode->height = pnode ->left ->height +1;
			else
				pnode ->height = pnode ->right ->height +1;
		}
		if(pnode -> height == oldHeight)
			finished  =1;
	}// end of while for rebalance

	return delNode;
}
示例#10
0
int m_tree_t::insertNode(int index, int otherIndex)
{
	node * newNode = getNode();
	newNode ->height = 0;
	newNode ->left = NULL;
	newNode ->right = NULL;
	newNode ->time = 1;
	newNode ->key = index;
	newNode ->ep_l.clear();
	newNode ->ep_r.clear();

	if(index < otherIndex)
		//newNode ->ep_r.insert(otherIndex);
		newNode ->ep_r.add(otherIndex);
	else
		//newNode ->ep_l.insert(otherIndex);
		newNode ->ep_l.add(otherIndex);



	node ** stack = new node* [num];
	int sindex = -1;

	node *pnode = NULL;
	if(root ->left == NULL)
	{
		root ->left =newNode;
		root ->key = index;
		root ->right = NULL;
		root ->height = 0;

		newNode ->nodeIvl_l = root ->nodeIvl_l;
		newNode ->nodeIvl_r = root ->key;

		getLeftMin(root);
		getRightMax(root);
		getMeasure(root);
	}
	else
	{
		pnode = root;
		while(pnode ->right != NULL)
		{
			sindex ++;
			stack[sindex] = pnode;
			if(index < pnode ->key)
				pnode = pnode ->left;
			else
				pnode = pnode ->right;
		}//end of while

		if(index == pnode ->key)
		{
			//for the case there same endpoint
			pnode ->left ->time ++;
			returnNode(newNode);

			// some ivtervals share  the same endpoint, then I store the correspondence endpoint in vector (STL)
			if(index <otherIndex)
			{
				pnode ->left ->ep_r.add(otherIndex);

				pnode ->left ->rightmax = pnode->left->ep_r.max();
				pnode ->rightmax = pnode ->left ->ep_r.max();
			}
			else
			{
				pnode ->left->ep_l.add(otherIndex);
				pnode ->left ->leftmin = pnode->left->ep_l.min();
				pnode ->leftmin = pnode ->left->ep_l.min();
			}

			pnode ->ep_l = pnode->left ->ep_l;
			pnode ->ep_r = pnode ->left ->ep_r;

			getLeftMin(pnode);
			getRightMax(pnode);
			getMeasure(pnode);


		}
		else
		{
			node * oldLeaf, *newLeaf;
			oldLeaf = getNode();
			oldLeaf->left = pnode ->left;
			oldLeaf ->key = pnode ->key;
			oldLeaf ->right = NULL;
			oldLeaf ->height = 0;


			newLeaf = getNode();
			newLeaf ->left = newNode;
			newLeaf ->key = index;
			newLeaf ->right = NULL;
			newLeaf ->height = 0;

			newLeaf ->ep_l = newNode ->ep_l;
			newLeaf ->ep_r = newNode ->ep_r;

			oldLeaf ->ep_l = pnode ->ep_l;
			oldLeaf ->ep_r = pnode ->ep_r;


			if(pnode ->key <= index)
			{
				pnode ->left = oldLeaf;
				pnode ->right = newLeaf;
				pnode ->key = index;
			}
			else
			{
				pnode ->left = newLeaf;
				pnode ->right = oldLeaf;
			}
			pnode ->height = 1;


			pnode ->left ->nodeIvl_l = pnode ->nodeIvl_l;
			pnode->left ->nodeIvl_r = pnode ->key;

			getLeftMin(pnode->left);
			getRightMax(pnode ->left);
			getMeasure(pnode ->left);

			pnode ->right ->nodeIvl_l = pnode ->key;
			pnode -> right->nodeIvl_r = pnode ->nodeIvl_r;

			getLeftMin(pnode ->right);
			getRightMax(pnode ->right);
			getMeasure(pnode ->right);

			getLeftMin(pnode);
			getRightMax(pnode);
			getMeasure(pnode);
		}//end of else

		int tmpInx = sindex;
		while(tmpInx > -1)
		{
			node* n = stack[tmpInx];
			tmpInx --;
			getLeftMin(n);
			getRightMax(n);
			getMeasure(n);
		}
	}// end of else


	//rebalance the tree
	int finished = 0;
	while(sindex > -1 && !finished)
	{
		int tmpHeight, oldHeight;
		node * ptrn = stack[sindex];
		sindex --;
		oldHeight = ptrn ->height;
		//getMeasure(ptrn);
		if(ptrn ->left ->height -ptrn->right ->height == 2)
		{
			if(ptrn->left->left->height - ptrn->right->height ==1)
			{
				rightR(ptrn);
				ptrn->right->height = ptrn ->right ->left ->height +1;
				ptrn ->height = ptrn->right ->height +1;
			}
			else
			{
				leftR(ptrn->left);
				rightR(ptrn);
				tmpHeight = ptrn ->left ->left ->height;
				ptrn ->left ->height = tmpHeight +1;
				ptrn ->right ->height = tmpHeight +1;
				ptrn ->height = tmpHeight +2;
			}
		}
		else if(ptrn->left->height - ptrn->right->height == -2)
		{
			if(ptrn->right->right->height - ptrn->left->height ==1 )
			{
				leftR(ptrn);
				ptrn ->left ->height = ptrn ->left ->right ->height +1;
				ptrn ->height = ptrn ->left ->height +1;
			}
			else
			{
				rightR(ptrn ->right);
				leftR(ptrn);
				tmpHeight = ptrn ->right ->right ->height;
				ptrn ->left ->height = tmpHeight +1;
				ptrn ->right ->height = tmpHeight +1;
				ptrn ->height = tmpHeight +2;
			}
		}
		else
		{
			if(ptrn ->left ->height > ptrn ->right ->height)
				ptrn->height = ptrn ->left ->height +1;
			else
				ptrn ->height = ptrn ->right ->height +1;
		}
		if(ptrn ->height == oldHeight)
			finished = 1;

	}//end of while

	//release the space for the stack
	delete stack;

	//increase the number for totall elements
	return num ++;
}
示例#11
0
	inline Spectrum sample(BSDFSamplingRecord &bRec, Float &_pdf, const Point2 &_sample) const {
		bool hasNested = (bRec.typeMask & m_nested->getType() & BSDF::EAll)
			&& (bRec.component == -1 || bRec.component < (int) m_components.size()-1);
		bool hasSpecular = (bRec.typeMask & EGlossyReflection)
			&& (bRec.component == -1 || bRec.component == (int) m_components.size()-1);

		bool choseSpecular = hasSpecular;
		Point2 sample(_sample);

		/* Evaluate the roughness texture */
		Float alpha = m_alpha->eval(bRec.its).average();
		Float alphaT = m_distribution.transformRoughness(alpha);

		Float probSpecular;
		if (hasSpecular && hasNested) {
			/* Find the probability of sampling the diffuse component */
			probSpecular = 1 - m_roughTransmittance->eval(std::abs(Frame::cosTheta(bRec.wi)), alpha);

			/* Reallocate samples */
			probSpecular = (probSpecular*m_specularSamplingWeight) /
				(probSpecular*m_specularSamplingWeight +
				(1-probSpecular) * (1-m_specularSamplingWeight));

			if (sample.y <= probSpecular) {
				sample.y /= probSpecular;
			} else {
				sample.y = (sample.y - probSpecular) / (1 - probSpecular);
				choseSpecular = false;
			}
		}

		if (choseSpecular) {
			/* Perfect specular reflection based on the microsurface normal */
			Normal m = m_distribution.sample(sample, alphaT);
			bRec.wo = reflect(bRec.wi, m);
			bRec.sampledComponent = (int) m_components.size() - 1;
			bRec.sampledType = EGlossyReflection;
			bRec.eta = 1.0f;

			/* Side check */
			if (Frame::cosTheta(bRec.wo) * Frame::cosTheta(bRec.wi) <= 0)
				return Spectrum(0.0f);
		} else {
			Vector wiBackup = bRec.wi;
			bRec.wi = refractTo(EInterior, bRec.wi);
			Spectrum result = m_nested->sample(bRec, _pdf, sample);
			bRec.wi = wiBackup;
			if (result.isZero())
				return Spectrum(0.0f);
			bRec.wo = refractTo(EExterior, bRec.wo);
			if (bRec.wo.isZero())
				return Spectrum(0.0f);
		}

		/* Guard against numerical imprecisions */
		EMeasure measure = getMeasure(bRec.sampledType);
		_pdf = pdf(bRec, measure);

		if (_pdf == 0)
			return Spectrum(0.0f);
		else
			return eval(bRec, measure) / _pdf;
	}