#NEWLINE# @ classmethod #NEWLINE# def fromstring( cls , s , **kwargs ) : #NEWLINE# #INDENT# ' Returns a new Constraint from the given string.\n            Uppercase words indicate either a tag ("NN", "JJ", "VP")\n            or a taxonomy term (e.g., "PRODUCT", "PERSON").\n            Syntax:\n            ( defines an optional constraint, e.g., "(JJ)".\n            [ defines a constraint with spaces, e.g., "[Mac OS X | Windows Vista]".\n            _ is converted to spaces, e.g., "Windows_Vista".\n            | separates different options, e.g., "ADJP|ADVP".\n            ! can be used as a word prefix to disallow it.\n            * can be used as a wildcard character, e.g., "soft*|JJ*".\n            ? as a suffix defines a constraint that is optional, e.g., "JJ?".\n            + as a suffix defines a constraint that can span multiple words, e.g., "JJ+".\n            ^ as a prefix defines a constraint that can only match the first word.\n            These characters need to be escaped if used as content: "\\(".\n        ' #NEWLINE# C = cls ( ** kwargs ) #NEWLINE# s = s . strip ( ) #NEWLINE# s = s . strip ( '{}' ) #NEWLINE# s = s . strip ( ) #NEWLINE# for i in range ( 3 ) : #NEWLINE# #INDENT# if s . startswith ( '^' ) : #NEWLINE# #INDENT# s = s [ 1 : ] #NEWLINE# C . first = True #NEWLINE# #UNINDENT# if ( s . endswith ( '+' ) and ( not s . endswith ( '\\+' ) ) ) : #NEWLINE# #INDENT# s = s [ 0 : ( - 1 ) ] #NEWLINE# C . multiple = True #NEWLINE# #UNINDENT# if ( s . endswith ( '?' ) and ( not s . endswith ( '\\?' ) ) ) : #NEWLINE# #INDENT# s = s [ 0 : ( - 1 ) ] #NEWLINE# C . optional = True #NEWLINE# #UNINDENT# if ( s . startswith ( '(' ) and s . endswith ( ')' ) ) : #NEWLINE# #INDENT# s = s [ 1 : ( - 1 ) ] #NEWLINE# C . optional = True #NEWLINE# #UNINDENT# if ( s . startswith ( '[' ) and s . endswith ( ']' ) ) : #NEWLINE# #INDENT# s = s [ 1 : ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# s = re . sub ( '^\\\\\\^' , '^' , cls ) #NEWLINE# s = re . sub ( '\\\\\\+$' , '+' , s ) #NEWLINE# s = s . replace ( '\\_' , '&uscore;' ) #NEWLINE# s = s . replace ( '_' , ' ' ) #NEWLINE# s = s . replace ( '&uscore;' , '_' ) #NEWLINE# s = s . replace ( '&lparen;' , '(' ) #NEWLINE# s = s . replace ( '&rparen;' , ')' ) #NEWLINE# s = s . replace ( '&lbrack;' , '[' ) #NEWLINE# s = s . replace ( '&rbrack;' , ']' ) #NEWLINE# s = s . replace ( '&lcurly;' , '{' ) #NEWLINE# s = s . replace ( '&rcurly;' , '}' ) #NEWLINE# s = s . replace ( '\\(' , '(' ) #NEWLINE# s = s . replace ( '\\)' , ')' ) #NEWLINE# s = s . replace ( '\\[' , '[' ) #NEWLINE# s = s . replace ( '\\]' , ']' ) #NEWLINE# s = s . replace ( '\\{' , '{' ) #NEWLINE# s = s . replace ( '\\}' , '}' ) #NEWLINE# s = s . replace ( '\\*' , '*' ) #NEWLINE# s = s . replace ( '\\?' , '?' ) #NEWLINE# s = s . replace ( '\\+' , '+' ) #NEWLINE# s = s . replace ( '\\^' , '^' ) #NEWLINE# s = s . replace ( '\\|' , '&vdash;' ) #NEWLINE# s = s . split ( '|' ) #NEWLINE# s = [ v . replace ( '&vdash;' , '|' ) . strip ( ) for v in s ] #NEWLINE# for v in s : #NEWLINE# #INDENT# C . _append ( v ) #NEWLINE# #UNINDENT# return C