赞
踩
- from nltk import CFG
- import nltk
- from nltk.chunk.regexp import *
- from nltk.parse.stanford import StanfordParser
- # import re
-
- # nltk.download('maxent_ne_chunker')
- # nltk.download('words')
- # nltk.download('ieer')
- # 语法分析
- toy_grammar = nltk.CFG.fromstring(
- """
- S -> NP VP
- VP -> V NP
- V -> "eats" | "drinks"
- NP -> Det N
- Det -> "a" | "an" | "the"
- N -> "president" |"Obama" |"apple"| "coke"
- """)
- toy_grammar.productions()
- print(toy_grammar.productions())
- # S indicate the entire sentence
- # VP is verb phrase the
- # NP is noun phrase (chunk that has noun in it)
- # N some example nouns
- # V is verb
- # Det is determiner used in the sentences
-
- # 正则表达式语法分析器
- chunk_rules = ChunkRule("<.*>+", "chunk everything")
- # NP
- # Preposition
- # Verb
- # PP

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。