I want to do a very simple job: given a string containing pronouns, I want to resolve them.

For example, I want to turn the sentence "Mary has a little lamb. She is cute." into "Mary has a little lamb. Mary is cute.".

     I use jave and Stanford Coreference which a part of Stanford CORENLP. I have managed to write some of the code but I am unable to complete the code and finish the job. Below is some of the code which I have used. Any help and advice will be appreciated.

String file=" Mary has a little lamb. She is cute.";

            Properties props = new Properties();

            props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");

            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

            Annotation document = new Annotation(file);

            pipeline.annotate(document);

            List tokens = new ArrayList();

            List sentences = document.get(CoreAnnotations.SentencesAnnotation.class);

           for(CoreMap sentence: sentences)

              { 

                 Map graph = document.get(CorefChainAnnotation.class);

                 System.out.println(graph);

                 for (Map.Entry entry : graph.entrySet()) {

                   CorefChain c = (CorefChain) entry.getValue();

                   CorefMention cm = c.getRepresentativeMention();

                   System.out.println(c);

                   System.out.println(cm);

              }

        }               

More Mussa Omer's questions See All
Similar questions and discussions