Package com.jpetrak.gate.stringannotation.extendedgazetteer2.trie3

Examples of com.jpetrak.gate.stringannotation.extendedgazetteer2.trie3.Utils


    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

    parms.put("backendNr",2);
    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

    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: "+((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");
    eg.save(save);
    Factory.deleteResource(eg);
    eg = null;
    System.gc();
    System.out.println("Saving completed, trying to load into a new gaz store");
    before = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
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);
    FeatureGazetteer eg = (FeatureGazetteer)Factory.createResource(
            "com.jpetrak.gate.stringannotation.extendedgazetteer2.FeatureGazetteer", parms);
    // test matching directly
    Iterator<Lookup> ret = null;
    ret = eg.doMatch("some", true,true);
    System.out.println("Matching same: "+ret);
    // check that it works with a gazetteer list that does not have any features
    defFile = new File(testingDir,"extgaz3.def");
    gazURL = defFile.toURI().toURL();
    parms.put("configFileURL", gazURL);
    eg = (FeatureGazetteer)Factory.createResource(
        "com.jpetrak.gate.stringannotation.extendedgazetteer2.FeatureGazetteer", parms);
    ret = eg.doMatch("word", true,true);
    System.out.println("Matching extgaz3 'word': "+eg.lookups2FeatureMaps(ret));
    ret = eg.doMatch("word", false,false);
    System.out.println("Matching extgaz3 'word': "+eg.lookups2FeatureMaps(ret));
    ret = eg.doMatch("word", true,true);
    System.out.println("Matching extgaz3 'word': "+eg.lookups2FeatureMaps(ret));
    ret = eg.doMatch("notthere", true,true);
    System.out.println("Matching extgaz3 'notthere': "+eg.lookups2FeatureMaps(ret));
    ret = eg.doMatch("test", true,true);
    System.out.println("Matching extgaz3 'test': "+eg.lookups2FeatureMaps(ret));
    ret = eg.doMatch("text", true,true);
    System.out.println("Matching extgaz3 'text': "+eg.lookups2FeatureMaps(ret));
    ret = eg.doMatch("thewordyes", false,false);
    System.out.println("Matching extgaz3 'thewordyes': "+eg.lookups2FeatureMaps(ret));
   
    System.out.println("Feature Gazetteer application test finished");
  }
View Full Code Here

    gs.runImplementationTests();
  }
 
  @Test
  public void testTrie2() {
    GazStore gs = new GazStoreTrie2();
    FeatureMap fm = Factory.newFeatureMap();
    fm.put("listFeature1","value1");
    fm.put("listFeature2","value2");
    int info1 = gs.addListInfo("Type1", "URL1", fm);
    String[] keyvals1 = new String[]{"key1","val1","key2","","k3","valuenumberthree"};
    /*
    State st1 = gs.addLookupOld("asdf", info1, keyvals1);
    Iterator<Lookup> it1 = gs.getLookups(st1);
    assertEquals(true,it1.hasNext());
View Full Code Here

    return listInfos.get(index).getFeatures();
  }
 
  @Override
  public int addListInfo(String type, String source, FeatureMap features) {
    listInfos.add(new ListInfo(type,source,features));
    return listInfos.size()-1;
  }
View Full Code Here

    return listInfos.get(index).getFeatures();
  }
 
  @Override
  public int addListInfo(String type, String source, FeatureMap features) {
    listInfos.add(new ListInfo(type,source,features));
    return listInfos.size()-1;
  }
View Full Code Here

TOP

Related Classes of com.jpetrak.gate.stringannotation.extendedgazetteer2.trie3.Utils

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.