How can I split a text into sentences using the Stanford parser?

后端 未结 12 1904
终归单人心
终归单人心 2020-11-27 14:52

How can I split a text or paragraph into sentences using Stanford parser?

Is there any method that can extract sentences, such as getSentencesFromString()

12条回答
  •  無奈伤痛
    2020-11-27 15:34

    With the Simple API provided by Stanford CoreNLP version 3.6.0 or 3.7.0.

    Here's an example with 3.6.0. It works exactly the same with 3.7.0.

    Java Code Snippet

    import java.util.List;
    
    import edu.stanford.nlp.simple.Document;
    import edu.stanford.nlp.simple.Sentence;
    public class TestSplitSentences {
        public static void main(String[] args) {
            Document doc = new Document("The text paragraph. Another sentence. Yet another sentence.");
            List sentences = doc.sentences();
            sentences.stream().forEach(System.out::println);
        }
    }
    

    Yields:

    The text paragraph.

    Another sentence.

    Yet another sentence.

    pom.xml

    
    
        4.0.0
    
        stanfordcorenlp
        stanfordcorenlp
        1.0-SNAPSHOT
    
        
            1.8
            1.8
        
    
        
            
            
                edu.stanford.nlp
                stanford-corenlp
                3.6.0
            
            
            
                com.google.protobuf
                protobuf-java
                2.6.1
            
        
    
    

提交回复
热议问题