本文整理汇总了Java中edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser类的典型用法代码示例。如果您正苦于以下问题:Java ShiftReduceParser类的具体用法?Java ShiftReduceParser怎么用?Java ShiftReduceParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShiftReduceParser类属于edu.stanford.nlp.parser.shiftreduce包,在下文中一共展示了ShiftReduceParser类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser; //导入依赖的package包/类
public static void main(String[] args) {
String modelPath = "ja.beam.rightmost.model.ser.gz";
List<String> restArgs = new ArrayList<>();
for (int argIndex = 0; argIndex < args.length; ) {
switch (args[argIndex]) {
case "-model":
modelPath = args[argIndex + 1];
argIndex += 2;
break;
case "-beamSize":
restArgs.add(args[argIndex]);
restArgs.add(args[argIndex + 1]);
argIndex += 2;
break;
default:
throw new RuntimeException("Unknown argument " + args[argIndex]);
}
}
String[] optionArray = restArgs.toArray(new String[restArgs.size()]);
RedwoodConfiguration.empty().capture(System.err).apply();
ShiftReduceParser model = ShiftReduceParser.loadModel(modelPath, optionArray);
RedwoodConfiguration.current().clear().apply();
String text = "";
String[] tokens = new String[0];
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
try {
text = scanner.nextLine();
if (text.isEmpty()) {
continue;
}
List<TaggedWord> taggedWords = new ArrayList<>();
tokens = text.split("(?<!\\\\) ");
if (0 == tokens.length) {
continue;
}
for (String token: tokens) {
TaggedWord taggedWord = new TaggedWord();
taggedWord.setFromString(token);
taggedWords.add(taggedWord);
}
Tree tree = model.apply(taggedWords);
System.out.println(tree);
} catch (Exception e) {
System.err.println("Tokens: " + Arrays.toString(tokens));
System.err.println(e.getMessage() + " with " + text);
//throw e;
}
}
}
示例2: StanfordSRParserThrift
import edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser; //导入依赖的package包/类
public StanfordSRParserThrift(String srParserModel)
{
model = ShiftReduceParser.loadModel(srParserModel);
tlp = new PennTreebankLanguagePack();
}