Package gate

Examples of gate.FeatureMap


          " which is non empty, number of documents contained: "+
          corpus.size());
      }
      // since this is a valid corpus, we adopt it by returning new
      // DocumentSubsetCorpus which has the original corpus as a parent
      FeatureMap parms = Factory.newFeatureMap();
      parms.put("directoryCorpus", ourCorpus);
      try {
        Resource newCorpus = Factory.createResource("at.ofai.gate.virtualcorpus.DirectorySubsetCorpus", parms, corpus.getFeatures(), corpus.getName());
        lr = (LanguageResource)newCorpus;
      } catch (ResourceInstantiationException ex) {
        throw new PersistenceException("Could not adopt corpus "+corpus.getName(),ex);
View Full Code Here


        }

        Long sPos = offset;
        Long ePos = offset + line.length();
        if (line.length() > 0 && line.trim().length() > 0) {
          FeatureMap features = Factory.newFeatureMap();
           document.getAnnotations(getInputAS()).add(sPos, ePos, getInputAnnotationType(), features);
          if (debugging) {
            System.out.println("Adding sentence:\n\t at (" + sPos
                + ", " + ePos + ")");
          }
View Full Code Here

  private void addConcept(Concept concept, Long sentenceStartPos) {
    Long conceptSPos = (long) concept.getOffset();
    Long sPos = sentenceStartPos + conceptSPos;
    Long ePos = sPos + (long) concept.getText().length();
    try {
      FeatureMap features = Factory.newFeatureMap();
      features.put("cn", concept.getName());
      features.put("cui", concept.getCode());
      features.put("definition", concept.getDefinition());
      features.put("preferredTerm", concept.getPreferredTerm().getText());
      features.put("synonyms", StringUtils.join(concept.getSynonyms(),";"));
      features.put("tuis", joinTuis(concept.getSemanticTypes()));
      features.put("stys", joinStys(concept.getSemanticTypes()));
      AnnotationSet nobleCoderSet = getDocument().getAnnotations(
          getOutputAS());
      nobleCoderSet.add(sPos, ePos, getOutputAnnotationType(), features);
    } catch (Exception x) {
      if (debugging) {
View Full Code Here

      int j = 0;
      for (Iterator iterator2 = tokenList.iterator(); iterator2.hasNext();) {
        Annotation token = (Annotation) iterator2.next();

        FeatureMap fm = token.getFeatures();
        fm.put("category", postags[j]);

        token.setFeatures(fm);

        j++;
View Full Code Here

      List<Annotation> token = new ArrayList<Annotation>( gateDoc.getAnnotations().get("Token", s.getStartNode().getOffset(), s.getEndNode().getOffset()) );
      Collections.sort(token, gate.Utils.OFFSET_COMPARATOR);
     
      for(int i = 0; i < token.size(); i++)
      {
        FeatureMap tAttributes = token.get(i).getFeatures();
        String str = gate.Utils.stringFor(gateDoc, token.get(i));   
        String orth = ""+tAttributes.get("orth"); if(orth.trim().equals("null")) {orth = "O";}
       
        //construct feature vectors
        aSentence += gateDoc.getName()+":"+token.get(i).getId() + "\t" + str +"\t"+ tAttributes.get("category") +
              "\t"+ tAttributes.get("chunk") + "\t" + tAttributes.get("kind") + "\t" + orth +
              "\t"+ getStem(str) + "\n";
      }
      featureFile.add(aSentence);
    }
    featureFile.add("\n");//insert empty line after each document
View Full Code Here

        String[] off = tagger.model.find(tokens, Collections.EMPTY_MAP);
            for (int i = 0; i < off.length; i++) {
              if (!off[i].equals("other")) {
                // /here is the logic to add annotation to gate

                FeatureMap fm = Factory.newFeatureMap();
                // type
                fm.put("source", "openNLP");
                // ok then add to string buff all the string to make
                // shure we got all the span
                // fm.put("string", text.substring(spans[i].getStart(),
                // spans[i]
                // .getEnd()));
                // fm.put("string",
                // tokenslist.get(spans[i].getStart()+1).getStartNode().getOffset(),
                // tokenslist.get(spans[i].getEnd()).getEndNode().getOffset());
                // source
                fm.put("type", tagger.name);

                // iterate until got the final span
                int start = i;
                int tmp = i + 1;
                if (off.length - 1 > tmp) {
                  // System.out.println("I am in if the value is: " +
                  // (off.length > tmp) + " the arr is: " + off.length
                  // + " " +
                  // "the index is: " + tmp);
                  try {
                    while (off[i + 1].equals("cont")) {
                      // while(off[++i].equals("cont"))
                      tmp = i + 1;
                      if (!(off.length - 1 > tmp))
                        break;
                      i++;
                    }
                  } catch (ArrayIndexOutOfBoundsException e) {
                    logger.error("Problem in doc "
                        + document.getName());
                    logger.error("The sentence is "
                        + sentence.toString());
                    logger.error("The named entity is at position "
                        + tmp);
                    continue;
                  }
                }

                try {
                  // annotations.add(Long.valueOf(tokens[start].get()),
                  // Long
                  // .valueOf(spans[i].getEnd()), "Name", fm);

                  // get the label

                  String label = document.getContent().getContent(
                      tokenslist.get(start).getStartNode()
                          .getOffset(),
                      tokenslist.get(i).getEndNode().getOffset())
                      .toString();

                  // add the label
                  fm.put("string", label);

                  // get the class uri
                  //String classUri = type2uri.get(tr.get(tagger.name));

                  // put the class
View Full Code Here

    {
      String str = gate.Utils.stringFor(gateDoc, s);
      result += gate.Utils.start(s) +"\t"+ gate.Utils.end(s) +"||string=" + str + "||type=problem" + "\n";
     
      //get attributes get them,
      FeatureMap tAttributes = s.getFeatures();
      if(!tAttributes.isEmpty())
        result += "conceptId=" + tAttributes.get("conceptId") + "||semType="+tAttributes.get("conceptId") + "||conceptName="+tAttributes.get("conceptName")+ "\n";

    }
   
    List<Annotation> as_treatment = new ArrayList<Annotation>( gateDoc.getAnnotations().get("treatment") );
    Collections.sort(as_treatment, gate.Utils.OFFSET_COMPARATOR);
    for(Annotation s: as_treatment)
    {
      String str = gate.Utils.stringFor(gateDoc, s);
      result += gate.Utils.start(s) +"\t"+ gate.Utils.end(s) +"||string=" + str + "||type=treatment" + "\n";
     
      //get attributes get them,
      FeatureMap tAttributes = s.getFeatures();
      if(!tAttributes.isEmpty())
        result += "conceptId=" + tAttributes.get("conceptId") + "||semType="+tAttributes.get("conceptId") + "||conceptName="+tAttributes.get("conceptName")+ "\n";

    }
   
    List<Annotation> as_test = new ArrayList<Annotation>( gateDoc.getAnnotations().get("test") );
    Collections.sort(as_test, gate.Utils.OFFSET_COMPARATOR);
    for(Annotation s: as_test)
    {
      String str = gate.Utils.stringFor(gateDoc, s);
      result += gate.Utils.start(s) +"\t"+ gate.Utils.end(s) +"||string=" + str + "||type=test" + "\n";
     
      //get attributes get them,
      FeatureMap tAttributes = s.getFeatures();
      if(!tAttributes.isEmpty())
        result += "conceptId=" + tAttributes.get("conceptId") + "||semType="+tAttributes.get("conceptId") + "||conceptName="+tAttributes.get("conceptName")+ "\n";
 
    }
   
      Factory.deleteResource(gateDoc); //N.B.!!
View Full Code Here

    // compare the resulting
    // spans and add annotations

    for (int i = 0; i < spans.length; i++) {

      FeatureMap fm = Factory.newFeatureMap();
      // type
      fm.put("source", "openNLP");
      fm.put("string", text.substring(spans[i].getStart(), spans[i]
          .getEnd()));
      // source
//      fm.put("type", "urn:lsid:ontotext.com:kim:iextraction:Token");

      try {
View Full Code Here

    // compare the resulting
    // sentences and add annotations
    int prevSpan = 0;
    for (int i = 0; i < spans.length; i++) {

      FeatureMap fm = Factory.newFeatureMap();
      // type
      fm.put("source", "openNLP");
      // source
      // fm.put("type", "urn:lsid:ontotext.com:kim:iextraction:Sentence");

      try {
        // annotations.add(Long.valueOf(spans[i].getStart()),
        // Long.valueOf(spans[i].getEnd()), "Sentence", fm);
        // annotations.add(i == 0 ? Long.valueOf(prevSpan) : Long
        // .valueOf(prevSpan + countSpaces(prevSpan - 1)),
        // i == (spans.length - 1) ? Long.valueOf(spans[i]) : Long
        // .valueOf(spans[i] - 1), "Sentence", fm);
        int start = prevSpan;
        int end = spans[i];

        // remove leading spaces of a sentence
        for (int j = start; j < end
            && Character.isWhitespace(text.charAt(j)); j++) {
          start = j + 1;
        }

        // remove trailing spaces of a sentence
        if (end > 1) {
          for (int j = end; j > start
              && Character.isWhitespace(text.charAt(j - 1)); j--) {
            end = j - 1;
          }
        }

        annotations.add(Long.valueOf(start), Long.valueOf(end),
            "Sentence", fm);
        if(!isSentenceSplitted)
          isSentenceSplitted = true;

      } catch (InvalidOffsetException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
      }

      prevSpan = spans[i];
    }
    if(!isSentenceSplitted){
      FeatureMap fm = Factory.newFeatureMap();
      // type
      fm.put("source", "openNLP");
      try {
        annotations.add(new Long(0), new Long(text.length()),
            "Sentence", fm);
      } catch (InvalidOffsetException e) {
        // TODO Auto-generated catch block
View Full Code Here

        for (Iterator iterator4 = annList.iterator(); iterator4
            .hasNext();) {
          Annotation token = (Annotation) iterator4.next();

          FeatureMap fm = token.getFeatures();
          fm.put("chunk", chunks[j]);

          token.setFeatures(fm);

          j++;
View Full Code Here

TOP

Related Classes of gate.FeatureMap

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.