本文整理汇总了Java中edu.stanford.nlp.util.StringUtils.argsToProperties方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.argsToProperties方法的具体用法?Java StringUtils.argsToProperties怎么用?Java StringUtils.argsToProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.argsToProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
* A debugging method to try relation extraction from the console.
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Properties props = StringUtils.argsToProperties(args);
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,regexner,parse,mention,coref,kbp");
props.setProperty("regexner.mapping", "ignorecase=true,validpospattern=^(NN|JJ).*,edu/stanford/nlp/models/kbp/regexner_caseless.tab;edu/stanford/nlp/models/kbp/regexner_cased.tab");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
IOUtils.console("sentence> ", line -> {
Annotation ann = new Annotation(line);
pipeline.annotate(ann);
for (CoreMap sentence : ann.get(CoreAnnotations.SentencesAnnotation.class)) {
sentence.get(CoreAnnotations.KBPTriplesAnnotation.class).forEach(System.err::println);
System.out.println(sentence);
}
});
}
示例2: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static void main(String[] args){
try{
Properties props = StringUtils.argsToProperties(args);
// props.setProperty("annotators", "tokenize,ssplit,lemma,pos,parse,ner");
StanfordCoreNLP pipeline = new StanfordCoreNLP();
String sentence = "John Gerspach was named Chief Financial Officer of Citi in July 2009.";
Annotation doc = new Annotation(sentence);
pipeline.annotate(doc);
RelationExtractorAnnotator r = new RelationExtractorAnnotator(props);
r.annotate(doc);
for(CoreMap s: doc.get(CoreAnnotations.SentencesAnnotation.class)){
System.out.println("For sentence " + s.get(CoreAnnotations.TextAnnotation.class));
List<RelationMention> rls = s.get(RelationMentionsAnnotation.class);
for(RelationMention rl: rls){
System.out.println(rl.toString());
}
}
}catch(Exception e){
e.printStackTrace();
}
}
示例3: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Properties props = StringUtils.argsToProperties(args);
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,regexner,parse,mention,coref,kbp");
props.setProperty("regexner.mapping", "ignorecase=true,validpospattern=^(NN|JJ).*,edu/stanford/nlp/models/kbp/regexner_caseless.tab;edu/stanford/nlp/models/kbp/regexner_cased.tab");
Set<String> interested = Stream.of("per:title", "per:employee_of", "org:top_members/employees").collect(Collectors.toSet());
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
IOUtils.console("sentence> ", line -> {
Annotation ann = new Annotation(line);
pipeline.annotate(ann);
for (CoreMap sentence : ann.get(CoreAnnotations.SentencesAnnotation.class)) {
sentence.get(CoreAnnotations.KBPTriplesAnnotation.class).forEach(r -> {
String relation = r.relationGloss();
if(interested.contains(relation)) {
System.err.println(r);
}
});
}
});
}
示例4: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
* Run Phrasal from the command line.
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
final Properties options = StringUtils.argsToProperties(args);
final String configFile = options.containsKey("") ? (String) options.get("") : null;
options.remove("");
if ((options.size() == 0 && configFile == null) || options.containsKey("help") || options.containsKey("h")) {
System.err.println(usage());
System.exit(-1);
}
// by default, exit on uncaught exception
Thread.setDefaultUncaughtExceptionHandler((t, ex) -> {
logger.fatal("Uncaught top-level exception", ex);
System.exit(-1);
});
final Map<String, List<String>> configuration = getConfigurationFrom(configFile, options);
final Phrasal p = Phrasal.loadDecoder(configuration);
if (options.containsKey("text")) p.decode(new FileInputStream(new File(options.getProperty("text"))), true);
else p.decode(System.in, true);
}
示例5: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
* A main method for training and evaluating the postprocessor.
*
* @param args
*/
public static void main(String[] args) {
// Strips off hyphens
Properties options = StringUtils.argsToProperties(args, optionArgDefs());
if (options.containsKey("help") || args.length == 0) {
System.err.println(usage(GermanPostprocessor.class.getName()));
System.exit(-1);
}
int nThreads = PropertiesUtils.getInt(options, "nthreads", 1);
GermanPreprocessor preProcessor = new GermanPreprocessor();
GermanPostprocessor postProcessor = new GermanPostprocessor(options);
CRFPostprocessor.setup(postProcessor, preProcessor, options);
CRFPostprocessor.execute(nThreads, preProcessor, postProcessor);
}
示例6: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
* A main method for training and evaluating the postprocessor.
*
* @param args
*/
public static void main(String[] args) {
// Strips off hyphens
Properties options = StringUtils.argsToProperties(args, optionArgDefs());
if (options.containsKey("help") || args.length == 0) {
System.err.println(usage(FrenchPostprocessor.class.getName()));
System.exit(-1);
}
int nThreads = PropertiesUtils.getInt(options, "nthreads", 1);
FrenchPreprocessor preProcessor = new FrenchPreprocessor();
FrenchPostprocessor postProcessor = new FrenchPostprocessor(options);
CRFPostprocessor.setup(postProcessor, preProcessor, options);
CRFPostprocessor.execute(nThreads, preProcessor, postProcessor);
}
示例7: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
* A main method for training and evaluating the postprocessor.
*
* @param args
*/
public static void main(String[] args) {
// Strips off hyphens
Properties options = StringUtils.argsToProperties(args, optionArgDefs());
if (options.containsKey("help") || args.length == 0) {
System.err.println(usage(EnglishPostprocessor.class.getName()));
System.exit(-1);
}
int nThreads = PropertiesUtils.getInt(options, "nthreads", 1);
EnglishPreprocessor preProcessor = new EnglishPreprocessor();
EnglishPostprocessor postProcessor = new EnglishPostprocessor(options);
CRFPostprocessor.setup(postProcessor, preProcessor, options);
CRFPostprocessor.execute(nThreads, preProcessor, postProcessor);
}
示例8: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
* A main method for training and evaluating the postprocessor.
*
* @param args
*/
public static void main(String[] args) {
// Strips off hyphens
Properties options = StringUtils.argsToProperties(args, optionArgDefs());
if (options.containsKey("help") || args.length == 0) {
System.err.println(usage(SpanishPostprocessor.class.getName()));
System.exit(-1);
}
int nThreads = PropertiesUtils.getInt(options, "nthreads", 1);
SpanishPreprocessor preProcessor = new SpanishPreprocessor();
SpanishPostprocessor postProcessor = new SpanishPostprocessor(options);
CRFPostprocessor.setup(postProcessor, preProcessor, options);
CRFPostprocessor.execute(nThreads, preProcessor, postProcessor);
}
示例9: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Properties props = null;
int server_port = 4567; // This is SparkJava's default
if (args.length > 0) {
props = StringUtils.argsToProperties(args);
final String portString = props.getProperty("port");
if (portString != null) {
server_port = Integer.parseInt(portString);
}
}
System.out.println("Processed args");
runServer(props, server_port);
}
示例10: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Properties props = StringUtils.argsToProperties(args);
boolean verbose = Boolean.parseBoolean(props.getProperty("v", "False"));
String goldFilename = props.getProperty("g");
String systemFilename = props.getProperty("s");
if (goldFilename == null || systemFilename == null) {
System.err.println("Usage:\n\tjava ...DependencyScoring [-v True/False] -g goldFile -s systemFile\n");
System.err.println("\nOptions:\n\t-v verbose output");
System.exit(-1);
}
DependencyScoring goldScorer = new DependencyScoring(goldFilename);
List<Collection<TypedDependency>> systemDeps = DependencyScoring.readDeps(systemFilename);
Score score = goldScorer.score(systemDeps);
System.out.println(score.toString(verbose));
}
示例11: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
StringUtils.printErrInvocationString("CRFFeatureExporter", args);
Properties props = StringUtils.argsToProperties(args);
CRFClassifier crf = new CRFClassifier(props);
String inputFile = crf.flags.trainFile;
if (inputFile == null) {
System.err.println("Please provide input file using -trainFile");
System.exit(-1);
}
String outputFile = crf.flags.exportFeatures;
if (outputFile == null) {
System.err.println("Please provide output file using -exportFeatures");
System.exit(-1);
}
CRFFeatureExporter featureExporter = new CRFFeatureExporter(crf);
Collection<List<CoreLabel>> docs =
crf.makeObjectBankFromFile(inputFile, crf.makeReaderAndWriter());
crf.makeAnswerArraysAndTagIndex(docs);
featureExporter.printFeatures(outputFile, docs);
}
示例12: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
Properties options = StringUtils.argsToProperties(args, optionArgDefs());
String[] filenames = options.getProperty("","").split("\\s+");
if (filenames.length < 1 || filenames[0].length() == 0 || options.containsKey("h")
|| options.containsKey("help")) {
System.err.println(usage());
System.exit(-1);
}
MakeWordClasses mkWordCls = new MakeWordClasses(options);
mkWordCls.run(filenames);
mkWordCls.writeResults(System.out);
}
示例13: loadClassifier
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static CRFClassifier<CoreLabel> loadClassifier(String options) throws IllegalArgumentException {
String[] inputFlags = options.split(" ");
Properties props = StringUtils.argsToProperties(inputFlags);
SeqClassifierFlags flags = new SeqClassifierFlags(props);
CRFClassifier<CoreLabel> crfSegmenter = new CRFClassifier<>(flags);
if(flags.loadClassifier == null) {
throw new IllegalArgumentException("missing -loadClassifier flag for CRF preprocessor.");
}
crfSegmenter.loadClassifierNoExceptions(flags.loadClassifier, props);
crfSegmenter.loadTagIndex();
return crfSegmenter;
}
示例14: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
/**
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.print(usage());
System.exit(-1);
}
Properties options = StringUtils.argsToProperties(args, argDefs());
final double scale = PropertiesUtils.getDouble(options, "s", DEFAULT_SCALE);
final String orientation = options.getProperty("o", "utility");
final boolean risk = "risk".equals(orientation);
final String metricName = options.getProperty("m", DEFAULT_METRIC);
final String filename = options.getProperty("");
BasicNBestList nbestlists = new BasicNBestList(filename);
MulticoreWrapper<List<BasicNBestEntry>, List<Pair<Double, String>>> wrapper =
new MulticoreWrapper<List<BasicNBestEntry>, List<Pair<Double, String>>>(0, new Processor(metricName, risk, scale), true);
for (List<BasicNBestEntry> nbestlist : nbestlists) {
wrapper.put(nbestlist);
while (wrapper.peek()) {
DumpRescored(wrapper.poll());
}
}
wrapper.join();
while (wrapper.peek()) {
DumpRescored(wrapper.poll());
}
}
示例15: main
import edu.stanford.nlp.util.StringUtils; //导入方法依赖的package包/类
public static void main(String[] args) {
Properties options = StringUtils.argsToProperties(args, optionArgDefs());
String annotations = PropertiesUtils.get(options, "annotations", null, String.class);
boolean changepreps = PropertiesUtils.getBool(options, "changepreps", false);
int sentenceCount = CoreNLPCache.loadSerialized(annotations);
CoreMap sentence;
for (int i = 0; i < sentenceCount; i++) {
try {
sentence = CoreNLPCache.get(i);
if (sentence == null) {
System.out.println();
System.err.println("Empty sentence #" + i);
continue;
}
printDependencies(sentence, changepreps);
//System.err.println("---------------------------");
} catch (Exception e) {
System.err.println("SourceSentence #" + i);
e.printStackTrace();
return;
}
}
}