Package org.apache.uima.cas

Examples of org.apache.uima.cas.ConstraintFactory


  /**
   * Retrieves the annotations in the given span.
   */
  @Override
  public Collection<AnnotationFS> getAnnotation(Type type, Span span) {
    ConstraintFactory cf = getCAS().getConstraintFactory();

    Type annotationType = getCAS().getAnnotationType();

    FeaturePath beginPath = getCAS().createFeaturePath();
    beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
    FSIntConstraint beginConstraint = cf.createIntConstraint();
    beginConstraint.geq(span.getStart());

    FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath,
        beginConstraint);

    FeaturePath endPath = getCAS().createFeaturePath();
    endPath.addFeature(annotationType.getFeatureByBaseName("end"));
    FSIntConstraint endConstraint = cf.createIntConstraint();
    endConstraint.leq(span.getEnd());

    FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath,
        endConstraint);

    FSMatchConstraint strictType = new StrictTypeConstraint(type);

    FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin,
        embeddedEnd);

    FSMatchConstraint annotationInSpanAndStrictTypeConstraint = cf.and(
        annotatioInSpanConstraint, strictType);

    FSIndex allAnnotations = getCAS().getAnnotationIndex(type);

    FSIterator annotationInsideSpanIndex = getCAS().createFilteredIterator(
View Full Code Here


    }

  }

  public FSIterator<AnnotationFS> getFilteredBasicIterator(FSMatchConstraint constraint) {
    ConstraintFactory cf = cas.getConstraintFactory();
    FSMatchConstraint matchConstraint = cf.and(constraint, filter.getDefaultConstraint());
    return cas.createFilteredIterator(basicIt, matchConstraint);
  }
View Full Code Here

 
  /**
   * Retrieves the annotations in the given span.
   */
  static Collection<AnnotationFS> getAnnotation(CAS cas, Type type, Span span) {
    ConstraintFactory cf = cas.getConstraintFactory();

    Type annotationType = cas.getAnnotationType();

    FeaturePath beginPath = cas.createFeaturePath();
    beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
    FSIntConstraint beginConstraint = cf.createIntConstraint();
    beginConstraint.geq(span.getStart());

    FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath, beginConstraint);

    FeaturePath endPath = cas.createFeaturePath();
    endPath.addFeature(annotationType.getFeatureByBaseName("end"));
    FSIntConstraint endConstraint = cf.createIntConstraint();
    endConstraint.leq(span.getEnd());

    FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath, endConstraint);

    FSMatchConstraint strictType = new StrictTypeConstraint(type);

    FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin, embeddedEnd);

    FSMatchConstraint annotationInSpanAndStrictTypeConstraint =
            cf.and(annotatioInSpanConstraint, strictType);

    FSIndex<AnnotationFS> allAnnotations = cas.getAnnotationIndex(type);

    FSIterator<AnnotationFS> annotationInsideSpanIndex =
            cas.createFilteredIterator(allAnnotations.iterator(),
View Full Code Here

      maxInfillerRules = (Integer) params.get(MAX_INFILLER_RULES);

  }

  protected FSMatchConstraint getConstraint(CAS cas) {
    ConstraintFactory cf = cas.getConstraintFactory();
    final FSTypeConstraint constraint = cf.createTypeConstraint();

    for (String each : getFilterSet()) {
      constraint.add(each);
    }
    constraint.add(RutaEngine.BASIC_TYPE);
View Full Code Here

    }

  }

  public FSIterator<AnnotationFS> getFilteredBasicIterator(FSMatchConstraint constraint) {
    ConstraintFactory cf = cas.getConstraintFactory();
    FSMatchConstraint matchConstraint = cf.and(constraint, filter.getDefaultConstraint());
    return cas.createFilteredIterator(basicIt, matchConstraint);
  }
View Full Code Here

  /**
   * Retrieves the annotations in the given span.
   */
  @Override
  public Collection<AnnotationFS> getAnnotation(Type type, Span span) {
    ConstraintFactory cf = getCAS().getConstraintFactory();

    Type annotationType = getCAS().getAnnotationType();

    FeaturePath beginPath = getCAS().createFeaturePath();
    beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
    FSIntConstraint beginConstraint = cf.createIntConstraint();
    beginConstraint.geq(span.getStart());

    FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath, beginConstraint);

    FeaturePath endPath = getCAS().createFeaturePath();
    endPath.addFeature(annotationType.getFeatureByBaseName("end"));
    FSIntConstraint endConstraint = cf.createIntConstraint();
    endConstraint.leq(span.getEnd());

    FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath, endConstraint);

    FSMatchConstraint strictType = new StrictTypeConstraint(type);

    FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin, embeddedEnd);

    FSMatchConstraint annotationInSpanAndStrictTypeConstraint =
            cf.and(annotatioInSpanConstraint, strictType);

    FSIndex<AnnotationFS> allAnnotations = getCAS().getAnnotationIndex(type);

    FSIterator<AnnotationFS> annotationInsideSpanIndex =
            getCAS().createFilteredIterator(allAnnotations.iterator(),
View Full Code Here

      token.setFeatureValue(tokenTypeFeat, eosFS);
      cas.getIndexRepository().addFS(token);

      FSIterator<AnnotationFS> it = cas.getAnnotationIndex(tokenType).iterator();

      ConstraintFactory cf = this.cas.getConstraintFactory();
      FSTypeConstraint tc = cf.createTypeConstraint();
      tc.add(sepType);
      tc.add(eosType.getName());
      ArrayList<String> path = new ArrayList<String>();
      path.add(tokenTypeFeat.getShortName());
      FSMatchConstraint cons = cf.embedConstraint(path, tc);
      it = this.cas.createFilteredIterator(it, cons);
      int count = 0;
      for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
        ++count;
      }
View Full Code Here

 
  /**
   * Retrieves the annotations in the given span.
   */
  static Collection<AnnotationFS> getAnnotation(CAS cas, Type type, Span span) {
    ConstraintFactory cf = cas.getConstraintFactory();

    Type annotationType = cas.getAnnotationType();

    FeaturePath beginPath = cas.createFeaturePath();
    beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
    FSIntConstraint beginConstraint = cf.createIntConstraint();
    beginConstraint.geq(span.getStart());

    FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath, beginConstraint);

    FeaturePath endPath = cas.createFeaturePath();
    endPath.addFeature(annotationType.getFeatureByBaseName("end"));
    FSIntConstraint endConstraint = cf.createIntConstraint();
    endConstraint.leq(span.getEnd());

    FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath, endConstraint);

    FSMatchConstraint strictType = new StrictTypeConstraint(type);

    FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin, embeddedEnd);

    FSMatchConstraint annotationInSpanAndStrictTypeConstraint =
            cf.and(annotatioInSpanConstraint, strictType);

    FSIndex<AnnotationFS> allAnnotations = cas.getAnnotationIndex(type);

    FSIterator<AnnotationFS> annotationInsideSpanIndex =
            cas.createFilteredIterator(allAnnotations.iterator(),
View Full Code Here

 
  /**
   * Retrieves the annotations in the given span.
   */
  static Collection<AnnotationFS> getAnnotation(CAS cas, Type type, Span span) {
    ConstraintFactory cf = cas.getConstraintFactory();

    Type annotationType = cas.getAnnotationType();

    FeaturePath beginPath = cas.createFeaturePath();
    beginPath.addFeature(annotationType.getFeatureByBaseName("begin"));
    FSIntConstraint beginConstraint = cf.createIntConstraint();
    beginConstraint.geq(span.getStart());

    FSMatchConstraint embeddedBegin = cf.embedConstraint(beginPath, beginConstraint);

    FeaturePath endPath = cas.createFeaturePath();
    endPath.addFeature(annotationType.getFeatureByBaseName("end"));
    FSIntConstraint endConstraint = cf.createIntConstraint();
    endConstraint.leq(span.getEnd());

    FSMatchConstraint embeddedEnd = cf.embedConstraint(endPath, endConstraint);

    FSMatchConstraint strictType = new StrictTypeConstraint(type);

    FSMatchConstraint annotatioInSpanConstraint = cf.and(embeddedBegin, embeddedEnd);

    FSMatchConstraint annotationInSpanAndStrictTypeConstraint =
            cf.and(annotatioInSpanConstraint, strictType);

    FSIndex<AnnotationFS> allAnnotations = cas.getAnnotationIndex(type);

    FSIterator<AnnotationFS> annotationInsideSpanIndex =
            cas.createFilteredIterator(allAnnotations.iterator(),
View Full Code Here

   * @return
   */
  public FSIterator<Annotation> createFilteredIterator(
      int problemBegin, int problemEnd, Type sentenceType)
  {
    ConstraintFactory cf = jcas.getConstraintFactory();
    TypeSystem ts = jcas.getTypeSystem();
    Iterator<Type> it = ts.getTypeIterator();
    //Type annotationType = ts.getType(Annotation.class.getName()); // this returns "org.apache.uima.tcas.Annotation" which isn't in type system
    Type annotationType = ts.getType("uima.tcas.Annotation"); // should be safe to hard code this
    //System.err.println("annotation type: " + annotationType);
    Feature sentenceBeginFeature = annotationType.getFeatureByBaseName("begin");
    FeaturePath sentenceBeginFeaturePath = jcas.createFeaturePath();
    sentenceBeginFeaturePath.addFeature(sentenceBeginFeature);
   
    Feature sentenceEndFeature = annotationType.getFeatureByBaseName("end");
    FeaturePath sentenceEndFeaturePath = jcas.createFeaturePath();
    sentenceEndFeaturePath.addFeature(sentenceEndFeature);
   
    FSMatchConstraint beginAndEnd = constructConstraintByBeginEnd(
        problemBegin, problemEnd, cf, sentenceBeginFeaturePath,
        sentenceEndFeaturePath);
   
   
    FSTypeConstraint sentenceTypeConstraint = cf.createTypeConstraint();
    sentenceTypeConstraint.add(sentenceType);
   
    FSMatchConstraint beginAndEndAndType = cf.and(beginAndEnd, sentenceTypeConstraint);
   
    FSIterator<Annotation> filteredIterator =
        jcas.createFilteredIterator(jcas.getAnnotationIndex().iterator(),  beginAndEndAndType);
    return filteredIterator;
  }
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.ConstraintFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.