public void initializeNER() { try { co = new NERAnnotator(ViewNames.NER_CONLL); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public void labelData() { textAnnotation = tab.createTextAnnotation(data); nerAnnotator.addView(textAnnotation); view = textAnnotation.getView(nerAnnotator.getViewName()); }
/** * Return possible tag values that the NERAnnotator can produce. * * @return the set of string representing the tag values */ @Override public Set<String> getTagValues() { if (!isInitialized()) { doInitialize(); } Lexicon labelLexicon = this.params.taggerLevel1.getLabelLexicon(); Set<String> tagSet = new HashSet<String>(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; } }
/** * process the single input string, produce output on standard out if no output directory is * defined, or produce the output in the output directory by the same file name as the input * file, or if a specific output filename is specified, use that name. * * @param data the string to process * @throws Exception if anything goes wrong. */ private void processInputString(String data) throws Exception { data = StringEscapeUtils.unescapeHtml4(data); TextAnnotation ta = tab.createTextAnnotation(data); data = this.produceOutput(this.nerAnnotator.getView(ta), ta); this.getResultProcessor().publish(data, Long.toString(System.currentTimeMillis()) + ".txt"); }
/** * 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) { // set up the configuration if (ViewNames.NER_ONTONOTES.equals(getViewName())) nerRm = new NerOntonotesConfigurator().getConfig(nerRm); else nerRm = new NerBaseConfigurator().getConfig(nerRm); this.params = Parameters.readConfigAndLoadExternalData(nerRm); this.params.forceNewSentenceOnLineBreaks = false; // load the models. synchronized (LOADING_MODELS) { ModelLoader.load(nerRm, viewName, false, this.params); } }
/** * process the single input string, produce output on standard out if no output directory is * defined, or produce the output in the output directory by the same file name as the input * file, or if a specific output filename is specified, use that name. * * @param data the string to process * @throws Exception if anything goes wrong. */ private void processInputString(String data) throws Exception { data = StringEscapeUtils.unescapeHtml4(data); TextAnnotation ta = tab.createTextAnnotation(data); data = this.produceOutput(this.nerAnnotator.getView(ta), ta); this.getResultProcessor().publish(data, Long.toString(System.currentTimeMillis()) + ".txt"); }
/** * 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) { // set up the configuration if (ViewNames.NER_ONTONOTES.equals(getViewName())) nerRm = new NerOntonotesConfigurator().getConfig(nerRm); else nerRm = new NerBaseConfigurator().getConfig(nerRm); this.params = Parameters.readConfigAndLoadExternalData(nerRm); this.params.forceNewSentenceOnLineBreaks = false; // load the models. synchronized (LOADING_MODELS) { ModelLoader.load(nerRm, viewName, false, this.params); } }
/** * the viewName will be used as a KEY to instantiate/get the corresponding NER instance * * @param nonDefaultRm a non-null ResourceManager object containing non-default parameters for * the NER model named by the viewName parameter. * @param viewName assign a name to the NER view generated. As shipped, this should be * ViewNames.NER_CONLL or ViewNames.NER_ONTONOTES * @return an NERAnnotator with models instantiated according to the values of viewName and the * parameters in nonDefaultConfig. */ public static NERAnnotator buildNerAnnotator(ResourceManager nonDefaultRm, String viewName) { synchronized (nerAnnotatorMap) { NERAnnotator ner = nerAnnotatorMap.get(viewName); if (ner == null) { ner = new NERAnnotator(nonDefaultRm, viewName); nerAnnotatorMap.put(viewName, ner); } return ner; } } }
public TextAnnotation runNER(String s) { TextAnnotationBuilder tab; boolean splitOnHyphens = false; tab = new TokenizerTextAnnotationBuilder(new StatefulTokenizer(splitOnHyphens, false)); TextAnnotation ta = tab.createTextAnnotation("001", "001", s); try { co.getView(ta); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return ta; }
@Override public void labelData() { textAnnotation = tab.createTextAnnotation(data); nerAnnotator.addView(textAnnotation); view = textAnnotation.getView(nerAnnotator.getViewName()); }
SpanLabelView nerView = new SpanLabelView(getViewName(), ta);
/** * Return possible tag values that the NERAnnotator can produce. * * @return the set of string representing the tag values */ @Override public Set<String> getTagValues() { if (!isInitialized()) { doInitialize(); } Lexicon labelLexicon = this.params.taggerLevel1.getLabelLexicon(); Set<String> tagSet = new HashSet<String>(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; } }
/** * the viewName will be used as a KEY to instantiate/get the corresponding NER instance * * @param nonDefaultRm a non-null ResourceManager object containing non-default parameters for * the NER model named by the viewName parameter. * @param viewName assign a name to the NER view generated. As shipped, this should be * ViewNames.NER_CONLL or ViewNames.NER_ONTONOTES * @return an NERAnnotator with models instantiated according to the values of viewName and the * parameters in nonDefaultConfig. */ public static NERAnnotator buildNerAnnotator(ResourceManager nonDefaultRm, String viewName) { synchronized (nerAnnotatorMap) { NERAnnotator ner = nerAnnotatorMap.get(viewName); if (ner == null) { ner = new NERAnnotator(nonDefaultRm, viewName); nerAnnotatorMap.put(viewName, ner); } return ner; } } }
/** * process the single input string, produce output on standard out if no output directory is * defined, or produce the output in the output directory by the same file name as the input * file, or if a specific output filename is specified, use that name. * * @param data the string to process * @throws Exception if anything goes wrong. */ private void processInputString(String data) throws Exception { data = StringEscapeUtils.unescapeHtml4(data); TextAnnotation ta = tab.createTextAnnotation(data); data = this.produceOutput(this.nerAnnotator.getView(ta), ta); this.getResultProcessor().publish(data, Long.toString(System.currentTimeMillis()) + ".txt"); }
@Override public void labelData() { textAnnotation = tab.createTextAnnotation(data); nerAnnotator.addView(textAnnotation); view = textAnnotation.getView(nerAnnotator.getViewName()); }
if (ViewNames.NER_ONTONOTES.equals(getViewName())) nerRm = new NerOntonotesConfigurator().getConfig(nerRm); else
/** * Return possible tag values that the NERAnnotator can produce. * * @return the set of string representing the tag values */ @Override public Set<String> getTagValues() { if (!isInitialized()) { doInitialize(); } Lexicon labelLexicon = t1.getLabelLexicon(); Set<String> tagSet = new HashSet(); for (int i =0; i < labelLexicon.size(); ++i) { tagSet.add(labelLexicon.lookupKey(i).getStringValue()); } return tagSet; } }
/** * the viewName will be used as a KEY to instantiate/get the corresponding NER instance * * @param nonDefaultRm a non-null ResourceManager object containing non-default parameters for * the NER model named by the viewName parameter. * @param viewName assign a name to the NER view generated. As shipped, this should be * ViewNames.NER_CONLL or ViewNames.NER_ONTONOTES * @return an NERAnnotator with models instantiated according to the values of viewName and the * parameters in nonDefaultConfig. */ public static NERAnnotator buildNerAnnotator(ResourceManager nonDefaultRm, String viewName) { synchronized (nerAnnotatorMap) { NERAnnotator ner = nerAnnotatorMap.get(viewName); if (ner == null) { ner = new NERAnnotator(nonDefaultRm, viewName); nerAnnotatorMap.put(viewName, ner); } return ner; } } }
/** * process the single input file, produce output on standard out if no output directory is * defined, or produce the output in the output directory by the same file name as the input * file, or if a specific output filename is specified, use that name. * * @param infile * @throws Exception */ private void processInputFile(File infile) throws Exception { String s = InFile.readFileText(infile.toString()); s = StringEscapeUtils.unescapeHtml4(s); TextAnnotation ta = tab.createTextAnnotation(s); s = this.produceOutput(this.nerAnnotator.getView(ta), ta); this.getResultProcessor().publish(s, infile.getName()); }
SpanLabelView nerView = new SpanLabelView(getViewName(), ta);