[英]Resolve Coreference using Stanford Parser in .NET
基本上,我想要的是用實際實體替換文本中的所有代詞。
// Path to the folder with models extracted from `stanford-corenlp-3.7.0-models.jar`
var jarRoot = ...
// Text for processing
var text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";
// Annotation pipeline configuration
var props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
props.setProperty("ner.useSUTime", "0");
// We should change current directory, so StanfordCoreNLP could find all the model files automatically
var curDir = Environment.CurrentDirectory;
Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
Directory.SetCurrentDirectory(curDir);
// Annotation
var annotation = new Annotation(text);
pipeline.annotate(annotation);
var graph = annotation.get(new CorefChainAnnotation().getClass());
Console.WriteLine(graph);
到目前為止,我只能找到如何“漂亮地打印”它,但是我想進一步處理“圖形”的結果,但是我不知道如何實際解析“ annotation.get(新的CorefChainAnnotation())的結果。的getClass())”。 在Java中,據說它將返回Map <Integer,CorefChain>,但是我不知道它應該如何在C#中工作。
你有什么想法?
一旦有了注釋,便可以通過強制轉換獲得圖形。
Map graph = (Map)document.get(new CorefCoreAnnotations.CorefChainAnnotation().getClass());
var entrySetValues = graph.entrySet();
Iterator it = entrySetValues.iterator();
while (it.hasNext())
{
Map.Entry kvpair = (Map.Entry)it.next();
CorefChain corefChain = (CorefChain)kvpair.getValue();
var mentionsList = corefChain.getMentionsInTextualOrder() as ArrayList;
foreach (CorefMention mention in mentionsList)
{
string noun = mention.mentionSpan;
// do other stuff
}
it.remove();
}
對於C#,其想法是首先正確地轉換對象,從轉換對象中以ArrayList的形式獲取列表,在arraylist上循環,然后再次正確地轉換對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.