-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trying to get compound Pattern constraints to work
- Loading branch information
Sam Joseph
committed
Jul 27, 2012
1 parent
50590a8
commit ca4d008
Showing
5 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pattern.search import * | ||
from pattern.en import * | ||
|
||
def extract(statement): | ||
|
||
s = Sentence(parse(statement, relations=True, lemmata=True, light=True)) | ||
|
||
c1 = Constraint.fromstring("There be DT") | ||
c2 = Constraint.fromstring("NN+") | ||
c3 = Constraint.fromstring("(DT)") | ||
c4 = Constraint.fromstring("(RB) (JJ) NNP+") | ||
c5 = Constraint.fromstring("(call) (DT)") | ||
c6 = Constraint.fromstring("(RB) (JJ) (NNPS|NNP)+") | ||
p = Pattern(sequence=[c1, c2, c3, c4, c5, c6]) | ||
result = p.search(statement) | ||
#raise Exception(result) | ||
return result | ||
|
||
|
||
def basicExtract(statement): | ||
|
||
s = Sentence(parse(statement, relations=True, lemmata=True, light=True)) | ||
p = Pattern.fromstring('(DT) (RB) (JJ) NN+') | ||
result = p.search(s) | ||
return result | ||
|
||
def myExtract(statement): | ||
|
||
s = Sentence(parse(statement, relations=True, lemmata=True, light=True)) | ||
p = Pattern.fromstring('There be DT NN+') | ||
result = p.search(s) | ||
#raise Exception(result) | ||
return result | ||
|
||
|
||
def constraintSequenceExtract(statement): | ||
|
||
s = Sentence(parse(statement, relations=True, lemmata=True, light=True)) | ||
|
||
c1 = Constraint.fromstring("There be DT") | ||
c2 = Constraint.fromstring("NN+") | ||
p = Pattern(sequence=[c1, c2]) | ||
result = p.search(s) | ||
return result | ||
#raise Exception(result) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import unittest | ||
import os | ||
from extractor import * | ||
|
||
class TestExtractor(unittest.TestCase): | ||
|
||
def testUnrealEngine(self): | ||
match = extract("There is a game engine Unreal Engine") | ||
self.assertNotEqual(len(match),0,"no match found") # "game_engines", "Unreal Engine", {"name":"Unreal Engine","ident":"Unreal Engine"}) | ||
|
||
def testUnity3D(self): | ||
match = extract("There is a game engine Unity3D called Unity3D") | ||
self.assertNotEqual(len(match),0,"no match found") # "game_engines", "Unity3D", {"name":"Unity3D","ident":"Unity3D"}) | ||
|
||
def testBasicExtract(self): | ||
match = basicExtract('tasty cat food') | ||
self.assertNotEqual(len(match),0,"no match found") | ||
|
||
def testMyExtract(self): | ||
match = myExtract("There is a game engine") | ||
self.assertNotEqual(len(match),0,"no match found") | ||
|
||
def testConstraintSequenceExtract(self): | ||
match = constraintSequenceExtract("There is a game engine") | ||
self.assertNotEqual(len(match),0,"no match found") | ||
|
||
#Crysis - said no to use in an online class | ||
#Unity3d - http://www.studica.com/unity | ||
#Source http://source.valvesoftware.com/sourcesdk/sourceu.php | ||
#Unreal engine | ||
#Game Maker | ||
#Game Salad | ||
#Scirra | ||
#Torque 3d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters