http://blog.csdn.net/pipisorry/article/details/42976457
stanford-parser的使用
1、到斯坦福官方網(wǎng)站http://nlp.stanford.edu/software/lex-parser.shtml下載軟件包,解壓。
2、在eclipse中新建1個java project,把解壓得到根目錄下的stanford-parser.jar和stanford-parser⑶.*.*-models.jar兩個包導入項目到項目援用包中,
然后把解壓得到根目錄下的ParserDemo.java文件拷貝到項目的src中
DEMO的使用
1、直接運行該實例程序(英文語法解析):
1.直接點擊run就能夠運行
2.如果要String[] sent從文本輸入:
eclipse > run > run configuration > arguments > program arguments:
輸入: edu/stanford/nlp/models/lexparser/englishPCFG.ser.gzC:UsersminglanDesktoptest2.txt
test2.txt:
The screen is really big, but the price is too expensive!
The price is expensive, students don't buy it usually.
The screen is beautiful, but the price is not!
The screen is big and beautiful!
3.如果要測試中文的話,要以下修改:
(1)按需要把輸入改成要測試中文:
String[] sent = { "這", "是", "第1個", "測試", "句子", "。" };
(2)導入中文的解析模型文件:
Stringgrammar = args.length > 0 ? args[0] : "edu/stanford/nlp/models/lexparser/chinesePCFG.ser.gz";
(3)修改源文件中的部份代碼:
TreebankLanguagePacktlp = new ChineseTreebankLanguagePack();//PennTreebankLanguagePack();
如果報錯沒有retainTmpSubcategories參數(shù),在源文件中注釋掉該參數(shù):
String[] options = {"-maxLength", "80"};//, "-retainTmpSubcategories" };
2、Stanford Parser自帶圖形化操作界面
在windows操作系統(tǒng)下只要雙擊運行軟件根目錄下的lexparser-gui.bat文件(linux下為lexparser-gui.sh文件)
點擊“Load File”導入需要解析文件也能夠直接在上面大的輸入框中輸入要解析內(nèi)容,
在“Language”選項當選擇對應解析的語言。
點擊“Load Parser”載入模型文件,稍等片刻(載入模型文件可能需要幾秒鐘)進度條完成載入后“Parser”按鈕變成可用狀態(tài),點擊便可解上輸入框中高亮的內(nèi)容,解析得到的樹形結(jié)果在下框中顯示,
可以把結(jié)果輸出另存為文件。
3、Stanford Parser還提供了命令行的方式lexparser-gui.bat(win)和lexparser.sh(linux)具體使用見官方文檔:Stanford Parser FAQ
4、Stanford Parser有個在線的解釋效果示例在:http://nlp.stanford.edu:8080/parser/index.jsp
相干設(shè)置
Stanford parser句法樹分析時候占用內(nèi)存可能較大,所以要調(diào)劑eclipse虛擬內(nèi)存空間,方法是在“運行――運行――自變量――VM自變量中填上-Xms256M -Xmx800M”,大小就要看實際情況和機子性能。
當句子較長時會出現(xiàn)報“FactoredParser: exceeded MAX_ITEMS work limit [200000 items]; aborting.”毛病...
在options中把MAX_ITEMS設(shè)為1個更大的書,以下例子中為500000
經(jīng)常使用的標注解釋
CC: conjunction, coordinatin 表示連詞
CD: numeral, cardinal 表示基數(shù)詞
DT: determiner 表示限定詞
EX: existential there 存在句
FW: foreign word 外來詞
IN: preposition or conjunction, subordinating 介詞或從屬連詞
JJ: adjective or numeral, ordinal 形容詞或序數(shù)詞
JJR: adjective, comparative 形容詞比較級
JJS: adjective, superlative 形容詞最高級
LS: list item marker 列表標識
MD: modal auxiliary 情態(tài)助動詞
NN: noun, common, singular or mass
NNS: noun, common, plural
NNP: noun, proper, singular
NNPS: noun, proper, plural
PDT: pre-determiner 前位限定詞
POS: genitive marker 所有格標記
PRP: pronoun, personal 人稱代詞
PRP$: pronoun, possessive 所有格代詞
RB: adverb 副詞
RBR: adverb, comparative 副詞比較級
RBS: adverb, superlative 副詞最高級
RP: particle 小品詞
SYM: symbol 符號
TO:"to" as preposition or infinitive marker 作為介詞或不定式標記
UH: interjection 插入語
VB: verb, base form
VBD: verb, past tense
VBG: verb, present participle or gerund
VBN: verb, past participle
VBP: verb, present tense, not 3rd person singular
VBZ: verb, present tense,3rd person singular
WDT: WH-determiner WH限定詞
WP: WH-pronoun WH代詞
WP$: WH-pronoun, possessive WH所有格代詞
WRB:Wh-adverb WH副詞
ROOT:要處理文本的語句
IP:簡單從句
NP:名詞短語
VP:動詞短語
PU:斷句符,通常是句號、問號、感嘆號等標點符號
LCP:方位詞短語
PP:介詞短語
CP:由‘的’構(gòu)成的表示修飾性關(guān)系的短語
DNP:由‘的’構(gòu)成的表示所屬關(guān)系的短語
ADVP:副詞短語
ADJP:形容詞短語
DP:限定詞短語
QP:量詞短語
NN:經(jīng)常使用名詞
NR:固著名詞
NT:時間名詞
PN:代詞
VV:動詞
VC:是
CC:表示連詞
VE:有
VA:表語形容詞
AS:內(nèi)容標記(如:了)
VRD:動補復合詞
CD: 表示基數(shù)詞
DT: determiner 表示限定詞
EX: existential there 存在句
FW: foreign word 外來詞
IN: preposition or conjunction, subordinating 介詞或從屬連詞
JJ: adjective or numeral, ordinal 形容詞或序數(shù)詞
JJR: adjective, comparative 形容詞比較級
JJS: adjective, superlative 形容詞最高級
LS: list item marker 列表標識
MD: modal auxiliary 情態(tài)助動詞
PDT: pre-determiner 前位限定詞
POS: genitive marker 所有格標記
PRP: pronoun, personal 人稱代詞
RB: adverb 副詞
RBR: adverb, comparative 副詞比較級
RBS: adverb, superlative 副詞最高級
RP: particle 小品詞
SYM: symbol 符號
TO:”to” as preposition or infinitive marker 作為介詞或不定式標記
WDT: WH-determiner WH限定詞
WP: WH-pronoun WH代詞
WP$: WH-pronoun, possessive WH所有格代詞
WRB:Wh-adverb WH副詞
關(guān)系表示
abbrev: abbreviation modifier,縮寫
acomp: adjectival complement,形容詞的補充;
advcl : adverbial clause modifier,狀語從句修飾詞
advmod: adverbial modifier狀語
agent: agent,代理,1般有by的時候會出現(xiàn)這個
amod: adjectival modifier形容詞
appos: appositional modifier,同位詞
attr: attributive,屬性
aux: auxiliary,非主要動詞和助詞,如BE,HAVE SHOULD/COULD等到
auxpass: passive auxiliary 被動詞
cc: coordination,并列關(guān)系,1般取第1個詞
ccomp: clausal complement從句補充
complm: complementizer,引導從句的詞好重聚中的主要動詞
conj : conjunct,連接兩個并列的詞。
cop: copula。系動詞(如be,seem,appear等),(命題主詞與謂詞間的)連系
csubj : clausal subject,從主關(guān)系
csubjpass: clausal passive subject 主從被動關(guān)系
dep: dependent依賴關(guān)系
det: determiner決定詞,如冠詞等
dobj : direct object直接賓語
expl: expletive,主要是抓取there
infmod: infinitival modifier,動詞不定式
iobj : indirect object,非直接賓語,也就是所以的間接賓語;
mark: marker,主要出現(xiàn)在有“that” or “whether”“because”, “when”,
mwe: multi-word expression,多個詞的表示
neg: negation modifier否定詞
nn: noun compound modifier名詞組合情勢
npadvmod: noun phrase as adverbial modifier名詞作狀語
nsubj : nominal subject,名詞主語
nsubjpass: passive nominal subject,被動的名詞主語
num: numeric modifier,數(shù)值修飾
number: element of compound number,組合數(shù)字
parataxis: parataxis: parataxis,并列關(guān)系
partmod: participial modifier動詞情勢的修飾
pcomp: prepositional complement,介詞補充
pobj : object of a preposition,介詞的賓語
poss: possession modifier,所有情勢,所有格,所屬
possessive: possessive modifier,這個表示所有者和那個’S的關(guān)系
preconj : preconjunct,常常是出現(xiàn)在 “either”, “both”, “neither”的情況下
predet: predeterminer,前綴決定,常常是表示所有
prep: prepositional modifier
prepc: prepositional clausal modifier
prt: phrasal verb particle,動詞短語
punct: punctuation,這個很少見,但是保存下來了,結(jié)果當中不會出現(xiàn)這個
purpcl : purpose clause modifier,目的從句
quantmod: quantifier phrase modifier,數(shù)量短語
rcmod: relative clause modifier相干關(guān)系
ref : referent,唆使物,指代
rel : relative
root: root,最重要的詞,從它開始,根節(jié)點
tmod: temporal modifier
xcomp: open clausal complement
xsubj : controlling subject 掌控者
【POS Tagging】
PS:
from:http://blog.csdn.net/pipisorry/article/details/42976457
ref:http://www.verydemo.com/demo_c173_i1328.html