내 코드의 목적은 문서 (pdf 또는 doc 파일)를 제출하고 그 안에 모든 텍스트를 가져 오는 것입니다. stanford nlp가 분석 할 텍스트를 제공하십시오. 코드는 잘 작동합니다. 그러나 문서에 "Pardeep Kumar"와 같은 이름이 있다고 가정합니다. 다음 그것을 받았다 출력은이다java 용 스탠포드 nlp api : 전체가 아닌 부분으로 이름을 얻는 방법
Pardeep NNP PERSON
쿠마 NNP PERSON을
하지만 난 이렇게 될 원한다
Pardeep 쿠마 NNP 사람
어떻게해야합니까? 그게 실제로 어떻게 하나의 이름이나 비슷한 것을 만들어내는 두 단어가 인접 해 있는지 확인하는 것입니다. 어떻게 다른 단어로 나눌 수 있습니까? 당신은 entitymentions
주석 자를 사용하려면
public class readstuff {
public static void analyse(String data) {
// creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// create an empty Annotation just with the given text
Annotation document = new Annotation(data);
// run all Annotators on this text
pipeline.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
// System.out.println("word"+"\t"+"POS"+"\t"+"NER");
for (CoreMap sentence : sentences) {
// traversing the words in the current sentence
// a CoreLabel is a CoreMap with additional token-specific methods
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
// this is the text of the token
String word = token.get(CoreAnnotations.TextAnnotation.class);
// this is the POS tag of the token
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
// this is the NER label of the token
String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
if(ne.equals("PERSON") || ne.equals("LOCATION") || ne.equals("DATE"))
{
System.out.format("%32s%10s%16s",word,pos,ne);
System.out.println();
//System.out.println(word +" \t"+pos +"\t"+ne);
}
}
}
}
public static void main(String[] args) throws FileNotFoundException, IOException, TransformerConfigurationException{
JFileChooser window=new JFileChooser();
int a=window.showOpenDialog(null);
if(a==JFileChooser.APPROVE_OPTION){
String name=window.getSelectedFile().getName();
String extension = name.substring(name.lastIndexOf(".") + 1, name.length());
String data = null;
if(extension.equals("docx")){
XWPFDocument doc=new XWPFDocument(new FileInputStream(window.getSelectedFile()));
XWPFWordExtractor extract= new XWPFWordExtractor(doc);
//System.out.println("docx file reading...");
data=extract.getText();
//extract.getMetadataTextExtractor();
}
else if(extension.equals("doc")){
HWPFDocument doc=new HWPFDocument(new FileInputStream(window.getSelectedFile()));
WordExtractor extract= new WordExtractor(doc);
//System.out.println("doc file reading...");
data=extract.getText();
}
else if(extension.equals("pdf")){
//System.out.println(window.getSelectedFile());
PdfReader reader=new PdfReader(new FileInputStream(window.getSelectedFile()));
int n=reader.getNumberOfPages();
for(int i=1;i<n;i++)
{
//System.out.println(data);
data=data+PdfTextExtractor.getTextFromPage(reader,i);
}
}
else{
System.out.println("format not supported");
}
analyse(data);
}
}
}
내가 생각할 수있는 것은 사전에 인도어 이름이 사전에 없으므로 영어 단어인지 아닌지 여부를 알기 위해 사전을 사용할 수 있다는 것입니다. 사전에 없으면 요구 사항에 따라 인접하여 인쇄물을 변경할 수 있습니다. – Lokesh
고마워요,하지만 그게 대답이 아니에요. –