List of usage examples for edu.stanford.nlp.ie.crf CRFClassifier getClassifier
public static CRFClassifier<CoreLabel> getClassifier(String loadPath) throws IOException, ClassCastException, ClassNotFoundException
From source file:NERServer.java
License:Open Source License
public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("usage: java NERServer modelpath"); System.exit(1);/* w ww . j a v a2 s . c om*/ } CRFClassifier crf = CRFClassifier.getClassifier(args[0]); BufferedReader input = new BufferedReader(new InputStreamReader(System.in), 1); for (;;) { String ln = input.readLine(); if (ln == null) { break; } List<List<CoreLabel>> out = crf.classify(ln); for (List<CoreLabel> sentence : out) { for (CoreLabel word : sentence) { String label = word.get(CoreAnnotations.AnswerAnnotation.class); System.out.print(word.word() + '/' + label + ' '); } } System.out.print('\n'); } }
From source file:asap.textprocessing.TextProcessNamedEntitiesStanford.java
/** * * @param modelsPath/* ww w . j av a 2s .c om*/ * @param t */ protected TextProcessNamedEntitiesStanford(String modelsPath, Thread t) { super(modelsPath, t); for (String nerModelFilename : Config.getNerModelFilenames()) { AbstractSequenceClassifier<CoreLabel> classifier; try { classifier = CRFClassifier .getClassifier(Config.getStanfordModelsDirectory() + File.separatorChar + nerModelFilename); } catch (IOException | ClassCastException | ClassNotFoundException ex) { Logger.getLogger(TextProcessNamedEntitiesStanford.class.getName()).log(Level.SEVERE, null, ex); continue; } ners.add(classifier); } }
From source file:com.apexxs.neonblack.detection.CardinalDetector.java
License:Apache License
public CardinalDetector() { try {/* w w w .ja va2 s . c o m*/ File modelFile = new File(config.getResourceDirectory() + config.getStanfordModel()); this.classifier = CRFClassifier.getClassifier(modelFile); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.diskoverorta.osdep.StanfordNLP.java
License:Apache License
public StanfordNLP() { try {/* ww w .ja v a 2 s . c o m*/ if (ner7Classifier == null) ner7Classifier = CRFClassifier.getClassifier(ner7classifierName); if (ner3Classifier == null) ner3Classifier = CRFClassifier.getClassifier(ner3classifierName); if (pipeline == null) { Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); pipeline = new StanfordCoreNLP(props); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.search.MySearchHandler.java
License:Apache License
@Override public void init(PluginInfo info) { init(info.initArgs);/*from w w w . j ava 2s .c om*/ fieldSet = new HashSet<String>(); fieldSet.addAll(((NamedList) info.initArgs.get("searchFields")).getAll("searchField")); for (PluginInfo child : info.children) { if ("shardHandlerFactory".equals(child.type)) { this.shfInfo = child; break; } } exrelmap = readHashMapFromDisk((String) ((NamedList) info.initArgs.get("inputFiles")).get("exrelmap")); questypemap = readHashMapFromDisk( (String) ((NamedList) info.initArgs.get("inputFiles")).get("questypemap")); mappingmap = readHashMapFromDisk((String) ((NamedList) info.initArgs.get("inputFiles")).get("mappingmap")); // exrelmap = // readHashMapFromDisk("F:\\solr-4.6.0\\solr-4.6.0\\dist\\expandedRelations.properties"); // questypemap = // readHashMapFromDisk("F:\\solr-4.6.0\\solr-4.6.0\\dist\\questionTypeProbability.properties"); // mappingmap = // readHashMapFromDisk("F:\\solr-4.6.0\\solr-4.6.0\\dist\\Mappings150.properties"); try { classifier = CRFClassifier .getClassifier("edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz"); } catch (ClassCastException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); }
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordNamedEntityRecognizer.java
License:Open Source License
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); modelProvider = new CasConfigurableProviderBase<AbstractSequenceClassifier<CoreMap>>() { {/*from w w w . ja v a 2 s .c o m*/ setContextObject(StanfordNamedEntityRecognizer.this); setDefault(GROUP_ID, "de.tudarmstadt.ukp.dkpro.core"); setDefault(ARTIFACT_ID, "de.tudarmstadt.ukp.dkpro.core.stanfordnlp-model-ner-${language}-${variant}"); setDefaultVariantsLocation( "de/tudarmstadt/ukp/dkpro/core/stanfordnlp/lib/ner-default-variants.map"); setDefault(LOCATION, "classpath:/de/tudarmstadt/ukp/dkpro/core/stanfordnlp/lib/" + "ner-${language}-${variant}.properties"); setOverride(LOCATION, modelLocation); setOverride(LANGUAGE, language); setOverride(VARIANT, variant); } @Override protected AbstractSequenceClassifier<CoreMap> produceResource(URL aUrl) throws IOException { InputStream is = null; try { is = aUrl.openStream(); if (aUrl.toString().endsWith(".gz")) { // it's faster to do the buffering _outside_ the gzipping as here is = new GZIPInputStream(is); } AbstractSequenceClassifier<CoreMap> classifier = (AbstractSequenceClassifier<CoreMap>) CRFClassifier .getClassifier(is); if (printTagSet) { StringBuilder sb = new StringBuilder(); sb.append("Model contains [").append(classifier.classIndex.size()).append("] tags: "); List<String> tags = new ArrayList<String>(); for (String t : classifier.classIndex) { tags.add(t); } Collections.sort(tags); sb.append(StringUtils.join(tags, " ")); getContext().getLogger().log(INFO, sb.toString()); } return classifier; } catch (ClassNotFoundException e) { throw new IOException(e); } finally { closeQuietly(is); } } }; mappingProvider = new MappingProvider(); mappingProvider.setDefaultVariantsLocation( "de/tudarmstadt/ukp/dkpro/core/stanfordnlp/lib/ner-default-variants.map"); mappingProvider.setDefault(MappingProvider.LOCATION, "classpath:/de/tudarmstadt/ukp/dkpro/" + "core/stanfordnlp/lib/ner-${language}-${variant}.map"); mappingProvider.setDefault(MappingProvider.BASE_TYPE, NamedEntity.class.getName()); mappingProvider.setOverride(MappingProvider.LOCATION, mappingLocation); mappingProvider.setOverride(MappingProvider.LANGUAGE, language); mappingProvider.setOverride(MappingProvider.VARIANT, variant); }
From source file:edu.isi.mavuno.nlp.NLProcTools.java
License:Apache License
@SuppressWarnings("unchecked") public void initializeNETagger() throws IOException, ClassCastException, ClassNotFoundException { mNETagger = CRFClassifier.getClassifier(new GZIPInputStream( getClass().getClassLoader().getResourceAsStream(NLProcTools.DEFAULT_NER_MODEL))); }
From source file:edu.stanford.muse.index.NEROld.java
License:Apache License
public synchronized static void initialize() throws ClassCastException, IOException, ClassNotFoundException { if (classifier == null) { String serializedClassifier = "ner-eng-ie.crf-3-all2008.ser.gz"; classifier = CRFClassifier.getClassifier( new GZIPInputStream(NER.class.getClassLoader().getResourceAsStream(serializedClassifier))); }/*from www . j av a 2 s .c o m*/ }
From source file:edu.stanford.muse.index.NEROld.java
License:Apache License
public static void main(String args[]) throws ClassCastException, IOException, ClassNotFoundException { String serializedClassifier = "ner-eng-ie.crf-3-all2008.ser.gz"; classifier = CRFClassifier.getClassifier( new GZIPInputStream(NER.class.getClassLoader().getResourceAsStream(serializedClassifier))); // trainForLowerCase(); int x = countNames( "Rishabh has so far not taken to drama, so it was wonderful to see him involved and actively participating"); Util.ASSERT(x == 1); // fails if trained for lower case, passes if not }
From source file:edu.univalle.vigtech_ner.NER.java
public ArrayList<Entity> getEntities(String serializedClassifier, String text) { // TODO Auto-generated method stub if (serializedClassifier == "") serializedClassifier = PropertiesManager.getInstance().getProperty("default.classifier"); System.out.println("Holaaaa: " + serializedClassifier); File path = new File( Thread.currentThread().getContextClassLoader().getResource(serializedClassifier).getFile()); serializedClassifier = path.getAbsolutePath(); System.out.println(path);//from w w w .j av a 2s. c o m ArrayList<Entity> entities = new ArrayList<Entity>(); AbstractSequenceClassifier<CoreLabel> classifier = null; try { classifier = CRFClassifier.getClassifier(serializedClassifier); } catch (ClassCastException | ClassNotFoundException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* For either a file to annotate or for the hardcoded text example, this demo file shows two ways to process the output, for teaching purposes. For the file, it shows both how to run NER on a String and how to run it on a whole file. For the hard-coded String, it shows how to run it on a single sentence, and how to do this and produce an inline XML output format. */ String fileContents = text; List<List<CoreLabel>> out = classifier.classify(fileContents); String chunk = ""; String lastClass = "O"; for (List<CoreLabel> sentence : out) { for (CoreLabel word : sentence) { if (word.get(CoreAnnotations.AnswerAnnotation.class).equals("O")) { if (!lastClass.equals("O")) { Entity ent = new Entity(); ent.setEntity(chunk); ent.setEntityClass(lastClass); entities.add(ent); chunk = ""; lastClass = word.get(CoreAnnotations.AnswerAnnotation.class); } } else { chunk += " " + word; lastClass = word.get(CoreAnnotations.AnswerAnnotation.class); } } } return entities; }