Java Code Examples for de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence#getEnd()

The following examples show how to use de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence#getEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityFirstSentenceFeature.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override public Map<Integer, Double> extract(JCas jCas) {
  Map<Integer, Double> features = new HashMap<>();

  Collection<Sentence> sentences = JCasUtil.select(jCas, Sentence.class);
  // Check if the first real sentence contains the entity.
  int firstSentenceBegin = 0;
  int firstSentenceEnd = 0;
  //if (sentences.size() > 3) {
    Iterator<Sentence> itr = sentences.iterator();
    //itr.next();
    //itr.next();
    Sentence sentence = itr.next();
    firstSentenceBegin = sentence.getBegin();
    firstSentenceEnd = sentence.getEnd();
  //}

  boolean inFirstSentence = false;
  for (AidaEntity ae : entityMentions) {
    int offset = ae.getBegin();
    inFirstSentence = (offset >= firstSentenceBegin) && (offset < firstSentenceEnd);
    if (inFirstSentence) {
      break;
    }
    if (ae.getBegin() > firstSentenceEnd) {
      break;
    }
  }


  features.put(getId(), inFirstSentence ? 1.0 : 0.0);
  return features;
}
 
Example 2
Source File: Conll2003ReaderTcBmeow.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override
public void getNext(CAS cas) throws IOException, CollectionException {
	reader.getNext(cas);

	JCas jcas;
       try {
           jcas = cas.getJCas();
       }
       catch (CASException e) {
           throw new CollectionException(e);
       }

	for(Sentence sentence : JCasUtil.select(jcas, Sentence.class)) {
		TextClassificationSequence sequence = new TextClassificationSequence(jcas, sentence.getBegin(),
				sentence.getEnd());
		sequence.addToIndexes();

		for(Token token : JCasUtil.selectCovered(jcas, Token.class, sentence)){
			TextClassificationTarget unit = new TextClassificationTarget(jcas, token.getBegin(), token.getEnd());
			unit.setSuffix(token.getCoveredText());
			unit.addToIndexes();

			TextClassificationOutcome outcome = new TextClassificationOutcome(jcas, token.getBegin(), token.getEnd());
			outcome.setOutcome(getTextClassificationOutcome(jcas, unit));
			outcome.addToIndexes();
		}

	}
}
 
Example 3
Source File: Conll2003ReaderTc.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override
public void getNext(CAS cas) throws IOException, CollectionException {
	reader.getNext(cas);

	JCas jcas;
       try {
           jcas = cas.getJCas();
       }
       catch (CASException e) {
           throw new CollectionException(e);
       }

	for(Sentence sentence : JCasUtil.select(jcas, Sentence.class)) {
		TextClassificationSequence sequence = new TextClassificationSequence(jcas, sentence.getBegin(),
				sentence.getEnd());
		sequence.addToIndexes();

		for(Token token : JCasUtil.selectCovered(jcas, Token.class, sentence)){
			TextClassificationTarget unit = new TextClassificationTarget(jcas, token.getBegin(), token.getEnd());
			unit.setSuffix(token.getCoveredText());
			unit.addToIndexes();

			TextClassificationOutcome outcome = new TextClassificationOutcome(jcas, token.getBegin(), token.getEnd());
			outcome.setOutcome(getTextClassificationOutcome(jcas, unit));
			outcome.addToIndexes();
		}

	}
}