1fromlepl.matchers.variablesimportTraceVariables 2 3# The contents of this file are subject to the Mozilla Public License 4# (MPL) Version 1.1 (the "License"); you may not use this file except 5# in compliance with the License. You may obtain a copy of the License 6# at http://www.mozilla.org/MPL/ 7# 8# Software distributed under the License is distributed on an "AS IS" 9# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 10# the License for the specific language governing rights and 11# limitations under the License. 12# 13# The Original Code is LEPL (http://www.acooke.org/lepl) 14# The Initial Developer of the Original Code is Andrew Cooke. 15# Portions created by the Initial Developer are Copyright (C) 2009-2010 16# Andrew Cooke (andrew@acooke.org). All Rights Reserved. 17# 18# Alternatively, the contents of this file may be used under the terms 19# of the LGPL license (the GNU Lesser General Public License, 20# http://www.gnu.org/licenses/lgpl.html), in which case the provisions 21# of the LGPL License are applicable instead of those above. 22# 23# If you wish to allow use of your version of this file only under the 24# terms of the LGPL License and not to allow others to use your version 25# of this file under the MPL, indicate your decision by deleting the 26# provisions above and replace them with the notice and other provisions 27# required by the LGPL License. If you do not delete the provisions 28# above, a recipient may use your version of this file under either the 29# MPL or the LGPL License. 30 31''' 32Tests for the lepl.matchers.memo module. 33''' 34 35fromloggingimportbasicConfig,DEBUG 36fromtimeimporttime 37fromunittestimportTestCase 38 39fromleplimportDelayed,Any,Optional,Node,Literals,Eos,Or,Token 40 41 42# pylint: disable-msg=C0103, C0111, C0301, W0702, C0324, C0102, C0321 43# (dude this is just a test) 44 45

118119#basicConfig(level=DEBUG)120121classVerbPhrase(Node):pass122classDetPhrase(Node):pass123classSimpleTp(Node):pass124classTermPhrase(Node):pass125classSentence(Node):pass126127verb=Literals('knows','respects','loves')>'verb'128join=Literals('and','or')>'join'129proper_noun=Literals('helen','john','pat')>'proper_noun'130determiner=Literals('every','some')>'determiner'131noun=Literals('boy','girl','man','woman')>'noun'132133verbphrase=Delayed()134verbphrase+=verb|(verbphrase//join//verbphrase)>VerbPhrase135det_phrase=determiner//noun>DetPhrase136simple_tp=proper_noun|det_phrase>SimpleTp137termphrase=Delayed()138termphrase+=simple_tp|(termphrase//join//termphrase)>TermPhrase139sentence=termphrase//verbphrase//termphrase&Eos()>Sentence140141sentence.config.clear().left_memoize()142p=sentence.get_match_string()143print(p.matcher.tree())144145text='every boy or some girl and helen and john or pat knows ' \ 146'and respects or loves every boy or some girl and pat or ' \ 147'john and helen'148# text = 'every boy loves helen'149count=0150for_meaninginp(text):151count+=1152ifcount<3:153#print(_meaning[0][0])154pass155#print(count)156assertcount==392,count