2017-04-05 2 views
0

Fondamentalement, ce que je veux, c'est remplacer tous les pronoms d'un texte par l'entité actuelle.Résolution de la coréférence à l'aide de Stanford Parser dans .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); 

Jusqu'à présent, je ne pouvait trouver comment « pretty print », mais je voudrais traiter davantage le résultat de « graphique », mais je ne sais pas comment analyser en fait le résultat de « l'annotation. get (nouveau CorefChainAnnotation(). getClass()) ". En Java, il est dit qu'il retournera une carte < Entier, CorefChain>, mais je ne sais pas comment il est censé fonctionner en C#.

Avez-vous des idées?

Répondre

0

Une fois que vous avez l'annotation, vous obtenez le graphique en le moulant.

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(); 
} 

Pour C#, l'idée est d'abord jeté correctement un objet, obtenir la liste de l'objet moulé comme ArrayList, boucle sur le arraylist et jeté à nouveau correctement les objets.