Search in sources :

Example 1 with NerBaseConfigurator

use of edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator in project cogcomp-nlp by CogComp.

the class NerInitTest method testInit.

@Test
public void testInit() {
    Properties props = new Properties();
    props.setProperty(NerBaseConfigurator.GAZETTEER_FEATURES, "0");
    props.setProperty(NerBaseConfigurator.BROWN_CLUSTER_PATHS, "0");
    ResourceManager rm = (new NerBaseConfigurator()).getConfig(new ResourceManager(props));
    NERAnnotator ner = NerAnnotatorManager.buildNerAnnotator(rm, ViewNames.NER_CONLL);
    assertNotNull(ner);
    TextAnnotationBuilder tab = new TokenizerTextAnnotationBuilder(new StatefulTokenizer());
    TextAnnotation ta = tab.createTextAnnotation(TESTSTR);
    try {
        ner.getView(ta);
    } catch (AnnotatorException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assert (ta.hasView(ViewNames.NER_CONLL));
    assertEquals(ta.getView(ViewNames.NER_CONLL).getConstituents().size(), 2);
}
Also used : NerBaseConfigurator(edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator) TextAnnotationBuilder(edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder) TokenizerTextAnnotationBuilder(edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder) TokenizerTextAnnotationBuilder(edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder) StatefulTokenizer(edu.illinois.cs.cogcomp.nlp.tokenizer.StatefulTokenizer) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) Properties(java.util.Properties) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Test(org.junit.Test)

Example 2 with NerBaseConfigurator

use of edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator in project cogcomp-nlp by CogComp.

the class Parameters method readConfigAndLoadExternalData.

/**
     * This just calls {@link #readAndLoadConfig readAndLoadConfig}. The main difference is that it
     * assigns the result to {@link ParametersForLbjCode#currentParameters}. This is important:
     * <code>ParametersForLbjCode</code> is changed because of this.
     *
     * @param configFile the path to a config file, to be loaded by a <code>ResourceManager</code>.
     * @param areWeTraining this value determines whether or not this run will involve training a
     *        model. If we are training, then we make sure there exists a folder in which to put the
     *        trained model. If not, then we make sure the model exists.
     * @throws IOException if the <code>ResourceManager</code> doesn't load correctly.
     */
public static void readConfigAndLoadExternalData(String configFile, boolean areWeTraining) throws IOException {
    ResourceManager rm = new ResourceManager(configFile);
    String modelName = rm.getString("modelName");
    String modelDir = rm.getString("pathToModelFile");
    Map<String, String> nonDefaultProps = new HashMap<>();
    nonDefaultProps.put(NerBaseConfigurator.PATH_TO_MODEL, modelDir);
    NerBaseConfigurator baseConfigurator = new NerBaseConfigurator();
    NerOntonotesConfigurator ontonotesConfigurator = new NerOntonotesConfigurator();
    // settings
    switch(modelName) {
        case ViewNames.NER_CONLL:
            ParametersForLbjCode.currentParameters = readAndLoadConfig(baseConfigurator.getConfig(nonDefaultProps), areWeTraining);
            break;
        case ViewNames.NER_ONTONOTES:
            ParametersForLbjCode.currentParameters = readAndLoadConfig(baseConfigurator.getConfig(ontonotesConfigurator.getConfig(nonDefaultProps)), areWeTraining);
            break;
        default:
            ParametersForLbjCode.currentParameters = readAndLoadConfig(baseConfigurator.getConfig(rm), areWeTraining);
            break;
    }
}
Also used : NerBaseConfigurator(edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator) NerOntonotesConfigurator(edu.illinois.cs.cogcomp.ner.config.NerOntonotesConfigurator) ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager)

Example 3 with NerBaseConfigurator

use of edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator in project cogcomp-nlp by CogComp.

the class NERAnnotator method initialize.

/**
     * Superclass calls this method either on instantiation or at first call to getView(). Logging
     * has been disabled because non-static logger is not initialized at the time this is called if
     * non-lazy initialization is specified.
     * 
     * @param nerRm configuration parameters passed to constructor
     */
@Override
public void initialize(ResourceManager nerRm) {
    if (ViewNames.NER_ONTONOTES.equals(getViewName()))
        nerRm = new NerOntonotesConfigurator().getConfig(nerRm);
    else
        nerRm = new NerBaseConfigurator().getConfig(nerRm);
    ParametersForLbjCode.currentParameters.forceNewSentenceOnLineBreaks = false;
    Parameters.readConfigAndLoadExternalData(nerRm);
    // logger.info("Reading model file: {}",
    // ParametersForLbjCode.currentParameters.pathToModelFile + ".level1");
    NETaggerLevel1 tagger1 = new NETaggerLevel1(ParametersForLbjCode.currentParameters.pathToModelFile + ".level1", ParametersForLbjCode.currentParameters.pathToModelFile + ".level1.lex");
    NETaggerLevel2 tagger2 = null;
    if (ParametersForLbjCode.currentParameters.featuresToUse.containsKey("PredictionsLevel1")) {
        // logger.info("Reading model file: {}",
        // ParametersForLbjCode.currentParameters.pathToModelFile + ".level2");
        tagger2 = new NETaggerLevel2(ParametersForLbjCode.currentParameters.pathToModelFile + ".level2", ParametersForLbjCode.currentParameters.pathToModelFile + ".level2.lex");
    }
    this.t1 = tagger1;
    this.t2 = tagger2;
}
Also used : NerBaseConfigurator(edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator) NETaggerLevel2(edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel2) NETaggerLevel1(edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel1) NerOntonotesConfigurator(edu.illinois.cs.cogcomp.ner.config.NerOntonotesConfigurator)

Example 4 with NerBaseConfigurator

use of edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator in project cogcomp-nlp by CogComp.

the class NerTest method setUp.

@Before
public void setUp() throws Exception {
    try {
        Parameters.readConfigAndLoadExternalData(new NerBaseConfigurator().getDefaultConfig());
        ParametersForLbjCode.currentParameters.forceNewSentenceOnLineBreaks = false;
        logger.info("Reading model file : " + ParametersForLbjCode.currentParameters.pathToModelFile + ".level1");
        t1 = new NETaggerLevel1(ParametersForLbjCode.currentParameters.pathToModelFile + ".level1", ParametersForLbjCode.currentParameters.pathToModelFile + ".level1.lex");
        if (ParametersForLbjCode.currentParameters.featuresToUse.containsKey("PredictionsLevel1")) {
            logger.info("Reading model file : " + ParametersForLbjCode.currentParameters.pathToModelFile + ".level2");
            t2 = new NETaggerLevel2(ParametersForLbjCode.currentParameters.pathToModelFile + ".level2", ParametersForLbjCode.currentParameters.pathToModelFile + ".level2.lex");
        }
    } catch (Exception e) {
        System.err.println("Cannot initialise the test, the exception was: ");
        e.printStackTrace();
        fail();
    }
}
Also used : NerBaseConfigurator(edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator) NETaggerLevel2(edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel2) NETaggerLevel1(edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel1) Before(org.junit.Before)

Example 5 with NerBaseConfigurator

use of edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator in project cogcomp-nlp by CogComp.

the class Main method inputMenu.

/**
     * render the input menu to standard out.
     */
@Override
protected void inputMenu() {
    if (this.nerAnnotator == null) {
        System.out.println("Loading resources...");
        if (resourceManager == null)
            this.resourceManager = new NerBaseConfigurator().getDefaultConfig();
        this.nerAnnotator = new NERAnnotator(this.resourceManager, "CONLL_DEFAULT");
        System.out.println("Completed loading resources.");
    }
    // display the command prompt depending on the mode we are in.
    switch(inswitch) {
        case MENU:
            System.out.println();
            String outdesc;
            String indesc;
            String in;
            String out;
            if (indirectory == null) {
                indesc = "text entered from the command line";
                in = "standard in";
            } else {
                if (indirectory.exists()) {
                    if (indirectory.isDirectory()) {
                        indesc = "text from all files in directory \"" + indirectory + "\"";
                        in = indirectory + File.separator;
                    } else {
                        indesc = "text from file \"" + indirectory + "\"";
                        in = indirectory + "";
                    }
                } else {
                    indesc = "text from file \"" + indirectory + "\"";
                    in = indirectory.toString();
                }
            }
            if (outdirectory == null) {
                outdesc = "presenting results to the terminal";
                out = "standard out";
            } else {
                if (outdirectory.exists()) {
                    if (outdirectory.isDirectory()) {
                        outdesc = "storing results in directory \"" + outdirectory + "\"";
                        out = outdirectory + File.separator;
                    } else {
                        outdesc = "storing results in file \"" + outdirectory + "\"";
                        out = outdirectory.toString();
                    }
                } else {
                    outdesc = "storing results in file \"" + outdirectory + "\"";
                    out = outdirectory.toString();
                }
            }
            System.out.println("1 - select input [" + in + "]\n" + "2 - change output [" + out + "]\n" + "3 - annotate " + indesc + ", " + outdesc + ".\n" + "4 - show and modify configuration parameters.\n" + "q - exit the application.\n" + "Choose from above options: ");
            break;
        case ENTER_IN:
            System.out.println("Enter input filename, directory terminated by file separator, or blank for standard input \n: ");
            break;
        case ENTER_OUT:
            System.out.println("Enter output filename, directory terminated by file separator or blank for standard output \n: ");
            break;
        case ENTER_STRING:
            System.out.println(": ");
            break;
        case SHOW_CONFIG:
            System.out.println("\nConfiguration parameters: ");
            Properties p = this.resourceManager.getProperties();
            for (Entry<Object, Object> entry : p.entrySet()) System.out.println("    " + entry.getKey() + " = " + entry.getValue());
            System.out.print("Enter property name followed a space and the new value, a blank entry to return to the main menu.\n: ");
            break;
    }
}
Also used : NerBaseConfigurator(edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator) Properties(java.util.Properties)

Aggregations

NerBaseConfigurator (edu.illinois.cs.cogcomp.ner.config.NerBaseConfigurator)5 ResourceManager (edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager)2 NETaggerLevel1 (edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel1)2 NETaggerLevel2 (edu.illinois.cs.cogcomp.ner.LbjFeatures.NETaggerLevel2)2 NerOntonotesConfigurator (edu.illinois.cs.cogcomp.ner.config.NerOntonotesConfigurator)2 Properties (java.util.Properties)2 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)1 TextAnnotationBuilder (edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder)1 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)1 StatefulTokenizer (edu.illinois.cs.cogcomp.nlp.tokenizer.StatefulTokenizer)1 TokenizerTextAnnotationBuilder (edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder)1 Before (org.junit.Before)1 Test (org.junit.Test)1