Package com.jpetrak.gate.stringannotation.extendedgazetteer2

Examples of com.jpetrak.gate.stringannotation.extendedgazetteer2.State


    @Override
    public CompletionContext<State> buildContext(
        SelectionModel selection, DocumentParser parser) {
      JsonArray<Token> tokens = JsonCollections.createArray();
      State state = TestUtils.createMockState();
      tokens.add(new Token(null, NULL, ""));
      ParseResult<State> parseResult = new ParseResult<State>(tokens, state) {};
      return buildContext(
          new ParseUtils.ExtendedParseResult<State>(parseResult, ParseUtils.Context.IN_CODE));
    }
View Full Code Here


   * @param anchorToUpdate the optional anchor that this method will update
   */
  private boolean parseImplCm2(Line line, int lineNumber, int numLinesToProcess,
      @Nullable Anchor anchorToUpdate, ParsedTokensRecipient tokensRecipient) {

    State parserState = loadParserStateForBeginningOfLine(line);
    if (parserState == null) {
      return false;
    }

    Line previousLine = line.getPreviousLine();

    for (int numLinesProcessed = 0; line != null && numLinesProcessed < numLinesToProcess;) {
      State stateToSave = parserState;
      if (line.getText().length() > LINE_LENGTH_LIMIT) {
        // Save the initial state instead of state at the end of line.
        stateToSave = parserState.copy(codeMirrorParser);
      }

View Full Code Here

    parseImplCm2(line, -1, 1, null, tokensRecipient);
    return tokensRecipient.tokens;
  }

  int getIndentation(Line line) {
    State stateBefore = loadParserStateForBeginningOfLine(line);
    String textAfter = line.getText();
    textAfter = textAfter.substring(StringUtils.lengthOfStartingWhitespace(textAfter));
    return codeMirrorParser.indent(stateBefore, textAfter);
  }
View Full Code Here

   *
   * @return copy of corresponding parser state, or {@code null} if the state
   *         if not known yet (previous line wasn't parsed).
   */
  private <T extends State> T loadParserStateForBeginningOfLine(TaggableLine line) {
    State state;
    if (line.isFirstLine()) {
      state = codeMirrorParser.defaultState();
    } else {
      state = line.getPreviousLine().getTag(LINE_TAG_END_OF_LINE_PARSER_STATE_SNAPSHOT);
      state = (state == null) ? null : state.copy(codeMirrorParser);
    }

    @SuppressWarnings("unchecked")
    T result = (T) state;
    return result;
View Full Code Here

   *
   * @see #loadParserStateForBeginningOfLine
   */
  @Nullable
  String getInitialMode(@Nonnull TaggableLine line) {
    State state = loadParserStateForBeginningOfLine(line);
    if (state == null) {
      return null;
    }
    return codeMirrorParser.getName(state);
  }
View Full Code Here

    }
    return codeMirrorParser.getName(state);
  }

  private void saveEndOfLineParserState(Line line, State parserState) {
    State copiedParserState = parserState.copy(codeMirrorParser);
    line.putTag(LINE_TAG_END_OF_LINE_PARSER_STATE_SNAPSHOT, copiedParserState);
  }
View Full Code Here

    FeatureMap parms = Factory.newFeatureMap();
    File defFile = new File(testingDir,"extgaz2.def");
    URL gazURL = defFile.toURI().toURL();
    parms.put("configFileURL", gazURL);
    parms.put("backendNr",backendNr);
    ExtendedGazetteer2 eg = (ExtendedGazetteer2)Factory.createResource(
            "com.jpetrak.gate.stringannotation.extendedgazetteer2.ExtendedGazetteer2", parms);
    // load the document
    parms = Factory.newFeatureMap();
    File docFile = new File(testingDir,"extgaz2docprep.xml");
    parms.put("sourceUrl",docFile.toURI().toURL());
    Document doc = (Document)
         Factory.createResource("gate.corpora.DocumentImpl", parms);
    AnnotationSet lookups = doc.getAnnotations().get("OutType");
    assertEquals(0,lookups.size());
    // run the gazetteer on the document
    eg.setDocument(doc);
    eg.execute();
    // check if we got the correct annotations
    AnnotationSet tokens = doc.getAnnotations().get("Token");
    assertEquals(46,tokens.size());
    AnnotationSet sentences = doc.getAnnotations().get("Sentence");
    assertEquals(4,sentences.size());
    lookups = doc.getAnnotations().get("OutType");
    if(backendNr == 3) {
      assertEquals(12,lookups.size());
    } else {
      assertEquals(14,lookups.size());
    }
    int i = 1;
    FeatureMap fm;
    long from;
    long to;
    for(Annotation ann : gate.Utils.inDocumentOrder(lookups)) {
      //System.out.println("Annotation: "+ann);
      fm = ann.getFeatures();
      String inst = (String)fm.get("inst");
      String string = (String)fm.get("_string");
      from = ann.getStartNode().getOffset();
      to = ann.getEndNode().getOffset();
      if(i == 1) {
        assertEquals(8,from);
        assertEquals(12,to);
        assertEquals("i1",inst);
        assertEquals("some",string);
      } else if(i == 5) {
        assertEquals(26,from);
        assertEquals(34,to);
        assertEquals("i11",inst);
        assertEquals("word and",string);
      }
      i++;
    }
    doc.getAnnotations().removeAll(lookups);
    eg.setMatchAtWordStartOnly(false);
    eg.setMatchAtWordEndOnly(false);
    eg.execute();
    lookups = doc.getAnnotations().get("OutType");
    assertEquals(22,lookups.size());
    doc.getAnnotations().removeAll(lookups);
    eg.setLongestMatchOnly(false);
    eg.execute();
    lookups = doc.getAnnotations().get("OutType");
    assertEquals(26,lookups.size());
    System.out.println("Gazetteer application test 1 finished for backedn "+backendNr);
  }
View Full Code Here

    FeatureMap parms = Factory.newFeatureMap();
    File defFile = new File(testingDir,"annie/lists.def");
    URL gazURL = defFile.toURI().toURL();
    parms.put("configFileURL", gazURL);
    parms.put("backendNr",backendNr);
    ExtendedGazetteer2 eg = (ExtendedGazetteer2)Factory.createResource(
            "com.jpetrak.gate.stringannotation.extendedgazetteer2.ExtendedGazetteer2", parms);
    // load the document
    eg.setOutputAnnotationSet("EXT");
    parms = Factory.newFeatureMap();
    File docFile = new File(testingDir,"news1pre.xml");
    parms.put("sourceUrl",docFile.toURI().toURL());
    Document doc = (Document)
         Factory.createResource("gate.corpora.DocumentImpl", parms);
    AnnotationSet lookups = doc.getAnnotations("EXT").get("Lookup");
    assertEquals(0,lookups.size());
    // run the gazetteer on the document
    eg.setDocument(doc);
    eg.execute();
    AnnotationDiffer differ = new AnnotationDiffer();
    differ.setSignificantFeaturesSet(new HashSet<String>());
    AnnotationSet keys = doc.getAnnotations().get("Lookup");
    System.out.println("Lookups old: "+keys.size());
    AnnotationSet responses = doc.getAnnotations("EXT").get("Lookup");
View Full Code Here

    parms.put("backendNr",3);
    System.gc();
    long before = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
    System.out.println("Memory used before loading gazetteer: "+before);
    long startTime = System.currentTimeMillis();
    ExtendedGazetteer2 eg = (ExtendedGazetteer2)Factory.createResource(
            "com.jpetrak.gate.stringannotation.extendedgazetteer2.ExtendedGazetteer2", parms);
    long endTime = System.currentTimeMillis();
    System.gc();
    long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
    System.out.println("Memory used after loading gazetteer: "+after);
    System.out.println("Elapsed time for loading from lst: "+((endTime-startTime)/1000.0));
    System.out.println("Memory used up in between: "+(after-before));
    System.out.println("Saving to test-big.gazbin");
    File save = new File("test-big.gazbin");
    startTime = System.currentTimeMillis();
    eg.save(save);
    endTime = System.currentTimeMillis();
    Factory.deleteResource(eg);
    System.out.println("Elapsed time for saving to gazbin: "+((endTime-startTime)/1000.0));
    eg = null;
    System.gc();
View Full Code Here

    parms.put("backendNr",1);
    System.gc();
    long before = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
    System.out.println("Memory used before loading gazetteer: "+before);
    long startTime = System.currentTimeMillis();
    ExtendedGazetteer2 eg = (ExtendedGazetteer2)Factory.createResource(
            "com.jpetrak.gate.stringannotation.extendedgazetteer2.ExtendedGazetteer2", parms);
    long endTime = System.currentTimeMillis();
    System.gc();
    long after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
    Factory.deleteResource(eg);
View Full Code Here

TOP

Related Classes of com.jpetrak.gate.stringannotation.extendedgazetteer2.State

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.