我想使用stanford解析器在给定的句子中找到多个名词短语.我正在使用Java.
例句:
画质非常好.
现在我需要提取"图片质量".
有没有办法遍历依赖树来实现所需的结果?
另外,可以用XML格式的stanford解析器标签语句吗?
我是Java开发的新手.
有人可以使用Stanfords的自然语言处理Lexical Parser-开源Java代码详细阐述如何获得"语法关系"吗?
谢谢!
我正在Windows中进行NLP项目,问题是每当我从命令提示符运行Stanford CoreNLP时,生成给定输入文本文件的XML输出大约需要14-15秒.我认为这个问题是因为库需要花费很多时间才能加载.可以请有人解释问题是什么,如何解决这个问题,因为这个时间问题对我的项目来说是个大问题?
我在visual studio 2012下使用C#上的NLP Parser.NuGet安装得很好,可以编译简单的例子.我注意到模型加载器存在问题:
try
{
System.Console.WriteLine(System.IO.File.Exists(full) ? "File exists." : "File does not exist.");
LexicalizedParser lp = LexicalizedParser.loadModel(full);
lp.setOptionFlags(new String[] { "-maxLength", "80", "-retainTmpSubcategories" });
//if (!String.IsNullOrEmpty(fileName))
//DemoDP(lp, fileName);
//else
DemoAPI(lp);
}
catch (Exception e)
{
System.Console.WriteLine(e.Message);
throw e;
}
Run Code Online (Sandbox Code Playgroud)
我得到某种文件读取格式错误:
C:\ NLPTest\bin\x86\Debug\englishPCFG.ser.gz:期待BEGIN块; 拿到 ??
模型文件大约是8 MB,但我不知道这个模型文件的格式.有什么地方我可以下载的官方文件肯定会有效吗?
是否有任何在线文档解释斯坦福NLP解析器输出的标签?
我对NLP很新,而且对我来说似乎像NN,VBZ ......这样的标签以及像poss,nsubj这样的关系似乎遵循一种标准,因为我已经在其他解析器上看到了这个输出.
非常感谢!
对于我目前的任务,我正在使用Stanford NLP构建问答模块.是否有来自斯坦福的java api开发Q&A相关应用程序?有点像我第一次喂我的数据的地方就像
虎杀了狗一样.
在此之后,如果我问谁
杀谁狗?
老虎遇害了谁?
狗活着吗?
它回答的答案是虎,狗,没有
非常感谢.
我仍然在玩斯坦福大学的CoreNLP,我在Coreference分辨率的非常简单的测试中遇到了奇怪的结果.
给出两句话:
酒店有一个大浴室.这很干净.
我希望句子2中的"It"可以被句子1的"浴室"或至少"大浴室"所共处.
不幸的是,它指向"酒店",在我看来是错误的.
有没有办法解决这个问题?我需要训练任何东西,还是应该开箱即用?
Annotation a = getPipeline().getAnnotation("The hotel had a big bathroom. It was very clean.");
System.out.println(a.get(CorefChainAnnotation.class));
Run Code Online (Sandbox Code Playgroud)
输出:
{1 = CHAIN1 - [句子1中的"酒店",句子2中的"它"],2 = CHAIN2 - [句子1中的"大浴室"]}
非常感谢您的帮助.
我一直在寻找一种解决方案,使用Stanford CoreNLP(RegexNERAnnotator)从文本中提取电子邮件地址,电话号码...... 任何人都可以提供任何例子吗?
更新:04/11/2015: 实际上我应该问一下Stanford RegexNERAnnotator是否可以支持Java正则表达式.
用法示例:
final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
List<CoreLabel> tokens = ...;
TokenSequencePattern pattern = TokenSequencePattern.compile(EMAIL_PATTERN);
TokenSequenceMatcher matcher = pattern.getMatcher(tokens);
while (matcher.find()) {
String matchedString = matcher.group();
List<CoreMap> matchedTokens = matcher.groupNodes();
...
}
Run Code Online (Sandbox Code Playgroud)
它似乎不支持Java正则表达式:
Exception in thread "main" edu.stanford.nlp.ling.tokensregex.parser.TokenMgrError: Lexical error at line 1, column 1. Encountered: "^" (94), after : ""
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParserTokenManager.getNextToken(TokenSequenceParserTokenManager.java:1029)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.jj_ntk(TokenSequenceParser.java:3228)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexBasic(TokenSequenceParser.java:784)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexDisjConj(TokenSequenceParser.java:973)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegex(TokenSequenceParser.java:743)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexWithAction(TokenSequenceParser.java:1596)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.parseSequenceWithAction(TokenSequenceParser.java:37)
at edu.stanford.nlp.ling.tokensregex.TokenSequencePattern.compile(TokenSequencePattern.java:186)
at edu.stanford.nlp.ling.tokensregex.TokenSequencePattern.compile(TokenSequencePattern.java:169)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Stanford Core NLP获得实时推文的感性分数。目前,我正在获取实时推文。但是,当我将其提供给Stanford Core NLP程序时,出现了错误。
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;
public class NLP {
static StanfordCoreNLP pipeline;
public static void init() {
pipeline = new StanfordCoreNLP("MyPropFile.properties");
}
public static int findSentiment(String tweet) {
int mainSentiment = 0;
if (tweet != null && tweet.length() > 0) {
int longest = 0;
Annotation annotation = pipeline.process(tweet);
for (CoreMap sentence : annotation
.get(CoreAnnotations.SentencesAnnotation.class)) {
Tree tree = sentence
.get(SentimentCoreAnnotations.AnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
String …Run Code Online (Sandbox Code Playgroud) 我已从此链接下载了NER的最新版本.然后解压缩后,我运行了这个命令.
java -cp stanford-ner.jar edu.stanford.nlp.ie.crf.CRFClassifier -prop austen.prop
Run Code Online (Sandbox Code Playgroud)
这不起作用并得到以下异常.
CRFClassifier invoked on Mon Jul 25 06:56:22 EDT 2016 with arguments:
-prop austen.prop
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at edu.stanford.nlp.io.IOUtils.<clinit>(IOUtils.java:42)
at edu.stanford.nlp.util.StringUtils.argsToProperties(StringUtils.java:942)
at edu.stanford.nlp.util.StringUtils.argsToProperties(StringUtils.java:891)
at edu.stanford.nlp.ie.crf.CRFClassifier.main(CRFClassifier.java:2994)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
Run Code Online (Sandbox Code Playgroud)
在文件夹中,stanford-ner-2015-12-09还有另一个文件夹lib,它已经包含slf4j库但仍然没有执行上面的命令.我刚下载然后提取文件并运行该命令来制作模型,但是这个例外即将到来.如果你能帮助我,我将感谢你.
我有以下代码行初始化Stanford词法分析器。
lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
Run Code Online (Sandbox Code Playgroud)
仅当我将代码从Java SE应用程序移动到Java EE应用程序时,我才会遇到异常。
Caused by: java.lang.NoSuchMethodError: edu.stanford.nlp.util.Generics.newHashMap()Ljava/util/Map;
at edu.stanford.nlp.parser.lexparser.BinaryGrammar.init(BinaryGrammar.java:223)
at edu.stanford.nlp.parser.lexparser.BinaryGrammar.readObject(BinaryGrammar.java:211)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Run Code Online (Sandbox Code Playgroud)
这是怎么引起的,我该如何解决?