Stanford CoreNLP Library

Farnaz Ghassemi Toudeshki
2 min readMay 30, 2024

Stanford CoreNLP

  • Java library
  • part-of-speech (POS) tagger
  • named entity recognizer (NER)
  • coreference resolution system

1-Constituent tree

# set java path
import os
java_path = r'/usr/lib/jvm/java-8-oracle/jre/bin/java'
os.environ['JAVAHOME'] = java_path

# import NLTK wrapper
from nltk.parse.stanford import StanfordParser

# Create Parser instance
# scp = Stanford Constituency Parser
scp = StanfordParser(path_to_jar='path_to_jar',
path_to_models_jar='path_to_models_jar')

sentence = "Mr. Dursley was the director of a firm called Grunnings, which made drills."

# Apply the parser
parse_trees = list(scp.raw_parse(sentence))
print(parse_trees[0])

#pretty printing
from IPython.display import display
display(resultparse_trees[0])
# (stanfordCoreNLP)
# first run the server
# java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 80000

from pycorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('http://localhost:9000')

output = nlp.annotate(sent, properties={
'annotators': 'parse',
'outputFormat': 'json'
})

a = [s['parse'] for s in…

--

--