pattern.ru parser
@@ -82,3 +82,44 @@ from pattern.text.en import wordlist
sys.path.pop(0)
+#--- Russian PARSER --------------------------------------------------------------------------------
+
+
+class Parser(_Parser):
+
+ def find_tags(self, tokens, **kwargs):
+ if kwargs.get("tagset") in (PENN, None):
+ kwargs.setdefault("map", lambda token, tag: (token, tag))
+ if kwargs.get("tagset") == UNIVERSAL:
+ kwargs.setdefault("map", lambda token, tag: penntreebank2universal(token, tag))
+ return _Parser.find_tags(self, tokens, **kwargs)
+
+parser = Parser(
+ lexicon=os.path.join(MODULE, "en-lexicon.txt"), # A dict of known words => most frequent tag.
+ frequency=os.path.join(MODULE, "en-frequency.txt"), # A dict of word frequency.
+ model=os.path.join(MODULE, "en-model.slp"), # A SLP classifier trained on WSJ (01-07).
+ morphology=os.path.join(MODULE, "en-morphology.txt"), # A set of suffix rules (e.g., -ly = adverb).
+ context=os.path.join(MODULE, "en-context.txt"), # A set of contextual rules.
+ entities=os.path.join(MODULE, "en-entities.txt"), # A dict of named entities: John = NNP-PERS.
+ default=("NN", "NNP", "CD"),
+ language="en"
+)
+
+
+
+def tokenize(s, *args, **kwargs):
+ """ Returns a list of sentences, where punctuation marks have been split from words.
+ """
+ return parser.find_tokens(s, *args, **kwargs)
+
+
+def parse(s, *args, **kwargs):
+ """ Returns a tagged Unicode string.
+ """
+ return parser.parse(s, *args, **kwargs)
+
+
+def parsetree(s, *args, **kwargs):
+ """ Returns a parsed Text from the given string.
+ """
+ return Text(parse(s, *args, **kwargs))
\ No newline at end of file
