Пример #1
0
bool SemanticCorpusReader::AddWord(const Document_Sentence_Word& word,
                                   int sentence, const IntIntMap& vocab,
                                   const set<int>& pos,
                                   const IntIntMap& synsets, BaseDoc* doc) {
  // If this corpus has pos information *and* we filter on pos
  // *and* this pos isn't there, then skip this word
  if (word.has_pos() && pos.size() > 0 && pos.find(word.pos()) == pos.end())
    return false;

  int token = word.token();
  int normalized_synset = -1;
  if (word.has_synset()) {
    int synset = word.synset();
    assert(synsets.find(synset) != synsets.end());
    normalized_synset = synsets.find(synset)->second;
  }
  if (use_lemma_ && word.has_lemma()) token = word.lemma();
  if (vocab.find(token) == vocab.end()) return false;
  int normalized_token = vocab.find(token)->second;

  static_cast<SemMlSeqDoc*>(doc)->
    AddWord(sentence, normalized_token, normalized_synset);
  static_cast<SemMlSeqDoc*>(doc)->Addtfidf(sentence, word.tfidf());
  return true;
}
Пример #2
0
void TransferFunctionAlphaWidget::paintOpacityGraph(QPainter& painter)
{
	QPen pointPen, pointLinePen;
	pointPen.setColor(QColor(0, 0, 150));
	pointLinePen.setColor(QColor(150, 100, 100));

	// Go through each point and draw squares and lines
	IntIntMap opacityMap = mImageTF->getOpacityMap();

	QPoint lastScreenPoint;
	this->mPointRects.clear();
	for (IntIntMap::iterator opPoint = opacityMap.begin();
		 opPoint != opacityMap.end();
		 ++opPoint)
	{
	  // Get the screen (plot) position of this point
		AlphaPoint pt(opPoint->first, opPoint->second);
		QPoint screenPoint = this->alpha2screen(pt);

		// draw line from left edge to first point:
		if (opPoint==opacityMap.begin())
		{
			lastScreenPoint = QPoint(mPlotArea.left(), screenPoint.y());
		}

	  // Draw line from previous point
		painter.setPen(pointLinePen);
		painter.drawLine(lastScreenPoint, screenPoint);

	  // Draw the rectangle
	  QRect pointRect(screenPoint.x() - mBorder, screenPoint.y() - mBorder,
					  mBorder*2, mBorder*2);
	  if (opPoint->first==mSelectedAlphaPoint.position)
	  {
		  pointPen.setWidth(2);
		  painter.setPen(pointPen);
	  }
	  else
	  {
		  pointPen.setWidth(1);
		  painter.setPen(pointPen);
	  }
	  painter.drawRect(pointRect);
	  this->mPointRects[opPoint->first] = pointRect;

	  // Store the point
	  lastScreenPoint = screenPoint;
	}

	// draw a line from the last point to the right end
	QPoint screenPoint(mPlotArea.right(), lastScreenPoint.y());
	painter.setPen(pointLinePen);
	painter.drawLine(lastScreenPoint, screenPoint);

}
Пример #3
0
TransferFunctionAlphaWidget::AlphaPoint TransferFunctionAlphaWidget::selectPoint(QPoint pos)
{
	std::map<int, QRect>::iterator it = mPointRects.begin();
	for(;it != mPointRects.end(); ++it)
	{
		if (it->second.contains(pos))
		{
			AlphaPoint retval;
			retval.position = it->first;
			IntIntMap opactiyMap = mImageTF->getOpacityMap();
			if (opactiyMap.find(retval.position) != opactiyMap.end())
				retval.value = opactiyMap.find(retval.position)->second;
			return retval;
		}
	}

	return AlphaPoint();
}
Пример #4
0
std::pair<int,int> TransferFunctionAlphaWidget::findAllowedMoveRangeAroundAlphaPoint(int selectedPointIntensity)
{
	// constrain new point intensity between the two neigbours
	IntIntMap opacityMap = mImageTF->getOpacityMap();
	IntIntMap::iterator pointIterator = opacityMap.find(selectedPointIntensity);

	std::pair<int,int> range(mImage->getMin(), mImage->getMax());
	if (pointIterator!=opacityMap.begin())
	{
		IntIntMap::iterator prevPointIterator = pointIterator;
		--prevPointIterator;
		range.first = std::max(range.first, prevPointIterator->first + 1);
	}

	IntIntMap::iterator nextPointIterator = pointIterator;
	++nextPointIterator;
	if (nextPointIterator!=opacityMap.end())
	{
		range.second = std::min(range.second, nextPointIterator->first - 1);
	}

	return range;
}
Пример #5
0
bool CorpusReader::AddWord(const Document_Sentence_Word& word,
                           int sentence, const IntIntMap& vocab,
                           const set<int>& pos, const IntIntMap& synsets,
                           BaseDoc* doc) {
  // If this corpus has pos information *and* we filter on pos
  // *and* this pos isn't there, then skip this word
  if (word.has_pos() && pos.size() > 0 && pos.find(word.pos()) == pos.end())
    return false;

  int token = word.token();
  if (use_lemma_ && word.has_lemma()) token = word.lemma();
  if (use_bigram_) {
    if (word.bigram() == -1) return false;
    else
      token = word.bigram();
  }
  if (vocab.find(token) == vocab.end()) return false;
  int normalized_token = vocab.find(token)->second;

  doc->AddWord(sentence, normalized_token);
  doc->Addtfidf(sentence, word.tfidf());
  return true;
}