[ad_1]
I am new in NLP, I want to do POS tagging and then do find a specific structure within a text. I could manage POS tagging using Stanford NLP but, I can not extract the structure: NN/NNS +IN+DET+NN/NNS/NNP/NNPS
public static void main(String args[]) throws Exception
//input File
String contentFilePath = "";
//outputFile
String triplesFilePath = contentFilePath.substring(0, contentFilePath.length()-4)+"_postagg.txt";
//document to POS tagging
String content = getFileContent(contentFilePath);
Properties props = new Properties();
props.setProperty("annotators","tokenize, ssplit, pos");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// Annotate the document.
Annotation doc = new Annotation(content);
pipeline.annotate(doc);
// Annotate the document.
List<CoreMap> sentences = doc.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences)
for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class))
String word = token.get(CoreAnnotations.TextAnnotation.class);
// this is the POS tag of the token
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
System.out.println(word + "/" + pos);
}
[ad_2]
لینک منبع