Search in sources :

Example 11 with ResourceManager

use of edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager in project cogcomp-nlp by CogComp.

the class NerOntonotesConfigurator method getDefaultConfig.

// private static final String ONTONOTES_VIEW_NAME = ViewNames.NER_ONTONOTES;
@Override
public ResourceManager getDefaultConfig() {
    // treatAllFilesInFolderAsOneBigDocument false
    Properties props = new Properties();
    props.setProperty(NerBaseConfigurator.TREAT_ALL_FILES_AS_ONE, FALSE);
    props.setProperty(NerBaseConfigurator.PATH_TO_MODEL, DEFAULT_ONTONOTES_MODEL_PATH);
    props.setProperty(NerBaseConfigurator.LABEL_TYPES, ONTONOTES_LABEL_TYPES);
    props.setProperty(NerBaseConfigurator.MODEL_NAME, ONTONOTES_MODEL_NAME);
    return (new NerBaseConfigurator()).getConfig(new ResourceManager(props));
}
Also used : ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) Properties(java.util.Properties)

Example 12 with ResourceManager

use of edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager in project cogcomp-nlp by CogComp.

the class NamedEntityTagger method parseArguments.

/**
     * parse the arguments, only the directory.
     * 
     * @param args the arguments.
     * @throws IOException
     */
private void parseArguments(String[] args) throws IOException {
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.equals("-i")) {
            i++;
            if (args.length <= i) {
                parsingError(arg + " requires an argument that was not provided.");
            }
            indirectory = new File(args[i]);
            if (!indirectory.exists()) {
                parsingError(args[i] + " did not exist, the input directory must exist and contain plain text data files.");
            }
        } else if (arg.equals("-o")) {
            i++;
            if (args.length <= i) {
                parsingError(arg + " requires an argument that was not provided.");
            }
            outdirectory = new File(args[i]);
        } else if (arg.equals("-c")) {
            i++;
            if (args.length <= i) {
                parsingError(arg + " requires an argument that was not provided.");
            }
            File config = new File(args[i]);
            if (!config.exists()) {
                parsingError(arg + "The config file specified, \"" + args[i] + "\" did not exist.");
            }
            nerAnnotator = NerAnnotatorManager.buildNerAnnotator(new ResourceManager(args[i]), ViewNames.NER_CONLL);
        } else if (arg.equals("-t")) {
            i++;
            try {
                max = Integer.parseInt(args[i]);
            } catch (NumberFormatException nfe) {
                parsingError("\"-t\" must be followed by an integer number to limit the number of threads, \"" + args[i] + "\" is not numberic.");
            }
        } else {
            parsingError("\"" + arg + "\" is not a valid command line argument.");
        }
    }
    if (nerAnnotator == null) {
        parsingError("A configuration file must be specified with the \"-c\" option.");
    }
    if (outdirectory != null && !outdirectory.exists()) {
        if (indirectory == null)
            outdirectory.createNewFile();
        else if (indirectory.isDirectory()) {
            outdirectory.mkdirs();
        } else {
            // the input directory is a single file, the output directory will be likewise
            outdirectory.createNewFile();
        }
    }
}
Also used : ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) File(java.io.File) OutFile(edu.illinois.cs.cogcomp.ner.IO.OutFile) InFile(edu.illinois.cs.cogcomp.ner.IO.InFile)

Example 13 with ResourceManager

use of edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager in project cogcomp-nlp by CogComp.

the class TestPOS method main.

/**
     * Implements the program described above.
     *
     * @param args The command line parameters.
     **/
public static void main(String[] args) {
    // Parse the command line
    // if (args.length != 1) {
    // logger.error("usage: java edu.illinois.cs.cogcomp.lbj.pos.TestPOS <text file>");
    // System.exit(1);
    // }
    // String testingFile = args[0];
    ResourceManager rm = new POSConfigurator().getDefaultConfig();
    String testingFile = rm.getString("testData");
    TestDiscrete.testDiscrete(new TestDiscrete(), new POSTagger(), new POSLabel(), new POSBracketToToken(testingFile), true, 0);
}
Also used : TestDiscrete(edu.illinois.cs.cogcomp.lbjava.classify.TestDiscrete) ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) POSBracketToToken(edu.illinois.cs.cogcomp.lbjava.nlp.seg.POSBracketToToken)

Example 14 with ResourceManager

use of edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager in project cogcomp-nlp by CogComp.

the class TestPOSModels method main.

public static void main(String[] args) {
    ResourceManager rm = new POSConfigurator().getDefaultConfig();
    TestPOSModels test = new TestPOSModels(rm.getString("testData"));
    test.testAccuracy();
}
Also used : ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager)

Example 15 with ResourceManager

use of edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager in project cogcomp-nlp by CogComp.

the class SimpleGazetteerAnnotatorTest method testAddView.

/**
     * Test method for
     * {@link edu.illinois.cs.cogcomp.edison.annotators.SimpleGazetteerAnnotator#addView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)}
     * .
     * 
     * @throws URISyntaxException
     * @throws IOException
     * @throws AnnotatorException
     */
@Test
public void testAddView() throws IOException, URISyntaxException, AnnotatorException {
    SimpleGazetteerAnnotator sga = new SimpleGazetteerAnnotator(defaultRm);
    assertTrue("Wrong number of dictionaries loaded.", sga.dictionaries.size() == 1);
    assertTrue("Wrong number of dictionaries loaded.", sga.dictionariesIgnoreCase.size() == 1);
    TextAnnotation ta = tab.createTextAnnotation("I hail from the university of illinois at champaign urbana.");
    sga.addView(ta);
    SpanLabelView view = (SpanLabelView) ta.getView(ViewNames.TREE_GAZETTEER);
    List<Constituent> entities = view.getConstituents();
    Constituent c1 = entities.get(0);
    assertEquals(c1.toString(), "university of illinois");
    Constituent c2 = entities.get(1);
    assertEquals(c2.toString(), "university of illinois at champaign urbana");
    Constituent c3 = entities.get(2);
    assertEquals(c3.toString(), "illinois");
    Constituent c4 = entities.get(3);
    assertEquals(c4.toString(), "champaign");
    Constituent c5 = entities.get(4);
    assertEquals(c5.toString(), "urbana");
    assertEquals(c1.getLabel(), "organizations(IC)");
    assertEquals(c2.getLabel(), "organizations(IC)");
    assertEquals(c3.getLabel(), "places(IC)");
    assertEquals(c4.getLabel(), "places(IC)");
    assertEquals(c5.getLabel(), "places(IC)");
    Properties props = new Properties();
    props.setProperty(SimpleGazetteerAnnotatorConfigurator.PHRASE_LENGTH.key, "4");
    props.setProperty(SimpleGazetteerAnnotatorConfigurator.PATH_TO_DICTIONARIES.key, "/testgazetteers/");
    props.setProperty(SimpleGazetteerAnnotatorConfigurator.IS_LAZILY_INITIALIZED.key, SimpleGazetteerAnnotatorConfigurator.FALSE);
    sga = new SimpleGazetteerAnnotator(new ResourceManager(props));
    assertTrue("Wrong number of dictionaries loaded.", sga.dictionaries.size() == 1);
    assertTrue("Wrong number of dictionaries loaded.", sga.dictionariesIgnoreCase.size() == 1);
    ta = tab.createTextAnnotation("I hail from the university of illinois at champaign urbana.");
    sga.addView(ta);
    view = (SpanLabelView) ta.getView(ViewNames.TREE_GAZETTEER);
    entities = view.getConstituents();
    c1 = entities.get(0);
    assertEquals(c1.toString(), "university of illinois");
    c2 = entities.get(1);
    assertEquals(c2.toString(), "illinois");
    c3 = entities.get(2);
    assertEquals(c3.toString(), "champaign");
    c4 = entities.get(3);
    assertEquals(c4.toString(), "urbana");
    assertEquals(c1.getLabel(), "organizations(IC)");
    assertEquals(c2.getLabel(), "places(IC)");
    assertEquals(c3.getLabel(), "places(IC)");
    assertEquals(c4.getLabel(), "places(IC)");
    ta = tab.createTextAnnotation("I hail from the University of Illinois at champaign urbana.");
    sga.addView(ta);
    view = (SpanLabelView) ta.getView(ViewNames.TREE_GAZETTEER);
    entities = view.getConstituents();
    c1 = entities.get(0);
    assertEquals(c1.toString(), "University of Illinois");
    assertEquals(c1.getLabel(), "organizations");
    c2 = entities.get(1);
    assertEquals(c1.toString(), "University of Illinois");
    assertEquals(c1.getLabel(), "organizations");
}
Also used : ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView) Properties(java.util.Properties) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Aggregations

ResourceManager (edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager)28 Properties (java.util.Properties)14 Test (org.junit.Test)8 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)6 StatefulTokenizer (edu.illinois.cs.cogcomp.nlp.tokenizer.StatefulTokenizer)5 TokenizerTextAnnotationBuilder (edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder)5 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)4 ChunkerAnnotator (edu.illinois.cs.cogcomp.chunker.main.ChunkerAnnotator)3 DepAnnotator (edu.illinois.cs.cogcomp.depparse.DepAnnotator)3 NERAnnotator (edu.illinois.cs.cogcomp.ner.NERAnnotator)3 PipelineConfigurator (edu.illinois.cs.cogcomp.pipeline.common.PipelineConfigurator)3 Stanford331Configurator (edu.illinois.cs.cogcomp.pipeline.common.Stanford331Configurator)3 POSAnnotator (edu.illinois.cs.cogcomp.pos.POSAnnotator)3 PrepSRLAnnotator (edu.illinois.cs.cogcomp.prepsrl.PrepSRLAnnotator)3 POSTaggerAnnotator (edu.stanford.nlp.pipeline.POSTaggerAnnotator)3 ParserAnnotator (edu.stanford.nlp.pipeline.ParserAnnotator)3 IOException (java.io.IOException)3 TextAnnotationBuilder (edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder)2 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2 InFile (edu.illinois.cs.cogcomp.ner.IO.InFile)2