本文整理汇总了Java中edu.stanford.nlp.ie.AbstractSequenceClassifier类的典型用法代码示例。如果您正苦于以下问题:Java AbstractSequenceClassifier类的具体用法?Java AbstractSequenceClassifier怎么用?Java AbstractSequenceClassifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractSequenceClassifier类属于edu.stanford.nlp.ie包,在下文中一共展示了AbstractSequenceClassifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvertNERtoCLAVIN
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
/**
* Checks conversion of Stanford NER output format into
* {@link com.bericotech.clavin.resolver.ClavinLocationResolver}
* input format.
*
* @throws IOException
*/
@Test
public void testConvertNERtoCLAVIN() throws IOException {
InputStream mpis = this.getClass().getClassLoader().getResourceAsStream("models/english.all.3class.distsim.prop");
Properties mp = new Properties();
mp.load(mpis);
AbstractSequenceClassifier<CoreMap> namedEntityRecognizer =
CRFClassifier.getJarClassifier("/models/english.all.3class.distsim.crf.ser.gz", mp);
String text = "I was born in Springfield and grew up in Boston.";
List<Triple<String, Integer, Integer>> entitiesFromNER = namedEntityRecognizer.classifyToCharacterOffsets(text);
List<LocationOccurrence> locationsForCLAVIN = convertNERtoCLAVIN(entitiesFromNER, text);
assertEquals("wrong number of entities", 2, locationsForCLAVIN.size());
assertEquals("wrong text for first entity", "Springfield", locationsForCLAVIN.get(0).getText());
assertEquals("wrong position for first entity", 14, locationsForCLAVIN.get(0).getPosition());
assertEquals("wrong text for second entity", "Boston", locationsForCLAVIN.get(1).getText());
assertEquals("wrong position for second entity", 41, locationsForCLAVIN.get(1).getPosition());
}
示例2: SultanModified
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
public SultanModified(Set<StringPair> ppdb, AbstractSequenceClassifier<CoreLabel> classifier,
MaxentTagger tagger) {
this.ppdbFile = null;
this.classifierFile = null;
this.posClassifierFile = null;
this.ppdb = ppdb;
this.classifier = classifier;
this.tagger = tagger;
}
示例3: initialValue
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
protected AbstractSequenceClassifier<CoreLabel> initialValue() {
try {
return CRFClassifier.getClassifier(classifierFilePath);
} catch (final Exception exception) {
LOGGER.error(MessageCatalog._00052_CLASSIFIER_LOAD_FAILURE, classifierFilePath);
return NULL_OBJECT_CLASSIFIER;
}
}
示例4: classifier
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
@Override
AbstractSequenceClassifier<CoreLabel> classifier() {
synchronized(this) {
if (classifier == null) {
try {
classifier = CRFClassifier.getClassifier(classifierFilePath);
} catch (final Exception exception) {
LOGGER.error(MessageCatalog._00052_CLASSIFIER_LOAD_FAILURE, classifierFilePath);
classifier = NULL_OBJECT_CLASSIFIER;
}
}
return classifier;
}
}
示例5: setup
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void setup(Context context) throws IOException, InterruptedException {
super.setup(context);
numrecords = 0;
try {
classifier = ((AbstractSequenceClassifier<CoreLabel>) CRFClassifier.getClassifier(NERMapper.class.getResourceAsStream("/nl/surfsara/warcexamples/hadoop/wet/resources/english.all.3class.distsim.crf.ser")));
} catch (Exception e) {
logger.error(e);
}
}
示例6: classifyToString
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
public static String classifyToString(List<CoreMap> sentence, DocumentReaderAndWriter<CoreMap> readerAndWriter, AbstractSequenceClassifier classif) {
PlainTextDocumentReaderAndWriter.OutputStyle outFormat =
PlainTextDocumentReaderAndWriter.OutputStyle.fromShortName("inlineXML");
DocumentReaderAndWriter<CoreMap> tmp = readerAndWriter;
readerAndWriter = new PlainTextDocumentReaderAndWriter<CoreMap>();
readerAndWriter.init(classif.flags);
StringBuilder sb = new StringBuilder();
sb.append(((PlainTextDocumentReaderAndWriter<CoreMap>) readerAndWriter).getAnswers(sentence, outFormat, true));
return sb.toString();
}
示例7: createClassifier
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
private AbstractSequenceClassifier<CoreLabel> createClassifier() throws ClassCastException, ClassNotFoundException, IOException {
String classifierPath = classifierFile.getAbsolutePath();
return CRFClassifier.getClassifier(classifierPath);
}
示例8: setTagger
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
/**
* For internal use by the duplication mechanism only.
*/
@Sharable
public void setTagger(AbstractSequenceClassifier<CoreLabel> tagger) {
this.tagger = tagger;
}
示例9: getTagger
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
/**
* For internal use by the duplication mechanism only.
*/
public AbstractSequenceClassifier<CoreLabel> getTagger() {
return this.tagger;
}
示例10: getClassifier
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
private static AbstractSequenceClassifier<CoreLabel> getClassifier() {
String serializedClassifier = "Files/english.all.3class.distsim.crf.ser.gz";
AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier
.getClassifierNoExceptions(serializedClassifier);
return classifier;
}
示例11: getCharacters
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
/**
* Get the characters.
*
* @return an ArrayList of characters
*/
public ArrayList<Person> getCharacters() {
ArrayList<Person> people = new ArrayList<Person>();
Genderize api = GenderizeIoAPI.create();
AbstractSequenceClassifier<CoreLabel> classifier;
String fileContents;
List<Triple<String, Integer, Integer>> list;
HashSet<String> existingNames;
try {
classifier = CRFClassifier.getClassifier(CLASSIFIER);
fileContents = IOUtils.slurpFile(filename);
list = classifier.classifyToCharacterOffsets(fileContents);
existingNames = new HashSet<String>();
for (Triple<String, Integer, Integer> item : list) {
if (item.first().equals("PERSON")) {
String nameStr = fileContents.substring(item.second(),
item.third());
nameStr = nameStr.replace("\n", " ")
.replace("\r", " ")
.replaceAll("\\s+", " ")
.trim();
if (!existingNames.contains(nameStr)) {
existingNames.add(nameStr);
String[] names = nameStr.split(" ");
Person p = new Person();
p.setFirstname(names[0]);
if (names.length > 1) {
p.setLastname(names[1]);
}
NameGender gender = api.getGender(p.getFirstname());
if (gender.getGender() != null) {
p.setGender(gender.isMale() ? male : female);
} else {
p.setGender(getRandomGender());
}
people.add(p);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return people;
}
示例12: classifier
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
@Override
AbstractSequenceClassifier<CoreLabel> classifier() {
return classifiers.get();
}
示例13: getClassifier
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
public AbstractSequenceClassifier<?> getClassifier()
{
return TreeTagger.getSharedClassifier();
}
示例14: resolveStanfordEntities
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
/**
* Sometimes, you might already be using Stanford NER elsewhere in
* your application, and you'd like to just pass the output from
* Stanford NER directly into CLAVIN, without having to re-run the
* input through Stanford NER just to use CLAVIN. This example
* shows you how to very easily do exactly that.
*
* @throws IOException
* @throws ClavinException
*/
private static void resolveStanfordEntities() throws IOException, ClavinException {
/*#####################################################################
*
* Start with Stanford NER -- no need to get CLAVIN involved for now.
*
*###################################################################*/
// instantiate Stanford NER entity extractor
InputStream mpis = WorkflowDemoNERD.class.getClassLoader().getResourceAsStream("models/english.all.3class.distsim.prop");
Properties mp = new Properties();
mp.load(mpis);
AbstractSequenceClassifier<CoreMap> namedEntityRecognizer =
CRFClassifier.getJarClassifier("/models/english.all.3class.distsim.crf.ser.gz", mp);
// Unstructured text file about Somalia to be geoparsed
File inputFile = new File("src/test/resources/sample-docs/Somalia-doc.txt");
// Grab the contents of the text file as a String
String inputString = TextUtils.fileToString(inputFile);
// extract entities from input text using Stanford NER
List<Triple<String, Integer, Integer>> entitiesFromNER = namedEntityRecognizer.classifyToCharacterOffsets(inputString);
/*#####################################################################
*
* Now, CLAVIN comes into play...
*
*###################################################################*/
// convert Stanford NER output to ClavinLocationResolver input
List<LocationOccurrence> locationsForCLAVIN = convertNERtoCLAVIN(entitiesFromNER, inputString);
// instantiate the CLAVIN location resolver
ClavinLocationResolver clavinLocationResolver = new ClavinLocationResolver(new LuceneGazetteer(new File("./IndexDirectory")));
// resolve location entities extracted from input text
List<ResolvedLocation> resolvedLocations = clavinLocationResolver.resolveLocations(locationsForCLAVIN, 1, 1, false);
// Display the ResolvedLocations found for the location names
for (ResolvedLocation resolvedLocation : resolvedLocations)
System.out.println(resolvedLocation);
}
示例15: getClassifier
import edu.stanford.nlp.ie.AbstractSequenceClassifier; //导入依赖的package包/类
/**
* Gets the classifier to use for parsing text
*
* @param config
* The configuration object containing information about which classifier to use.
* @return The classifier to use for extracting entities.
*/
private AbstractSequenceClassifier<CoreLabel> getClassifier(String classifierStr) {
URL classifierURL = Resources.getResource(classifierStr);
AbstractSequenceClassifier<CoreLabel> classifier =
CRFClassifier.getClassifierNoExceptions(classifierURL.getPath());
return classifier;
}