├── 1.5 ├── commonTypes.py ├── commonTypesSub.py ├── frame.py ├── frameIndex.py ├── frameIndexSub.py ├── frameSub.py ├── fulltext.py ├── fulltextIndex.py ├── fulltextIndexSub.py ├── fulltextSub.py ├── header.py ├── headerSub.py ├── lexUnit.py ├── lexUnitSub.py ├── luIndex.py ├── luIndexSub.py ├── semTypes.py ├── semTypesSub.py ├── sentence.py └── sentenceSub.py ├── COPYING ├── README.md ├── framenet ├── __init__.py ├── frame.py ├── frame_relation.py ├── framenet.py ├── lexical_unit.py └── settings.py ├── setup.py └── test └── importer.py /1.5/commonTypes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Generated Fri Apr 15 15:55:47 2011 by generateDS.py version 2.4c. 6 | # 7 | 8 | import sys 9 | import getopt 10 | import re as re_ 11 | 12 | etree_ = None 13 | Verbose_import_ = False 14 | ( XMLParser_import_none, XMLParser_import_lxml, 15 | XMLParser_import_elementtree 16 | ) = range(3) 17 | XMLParser_import_library = None 18 | try: 19 | # lxml 20 | from lxml import etree as etree_ 21 | XMLParser_import_library = XMLParser_import_lxml 22 | if Verbose_import_: 23 | print("running with lxml.etree") 24 | except ImportError: 25 | try: 26 | # cElementTree from Python 2.5+ 27 | import xml.etree.cElementTree as etree_ 28 | XMLParser_import_library = XMLParser_import_elementtree 29 | if Verbose_import_: 30 | print("running with cElementTree on Python 2.5+") 31 | except ImportError: 32 | try: 33 | # ElementTree from Python 2.5+ 34 | import xml.etree.ElementTree as etree_ 35 | XMLParser_import_library = XMLParser_import_elementtree 36 | if Verbose_import_: 37 | print("running with ElementTree on Python 2.5+") 38 | except ImportError: 39 | try: 40 | # normal cElementTree install 41 | import cElementTree as etree_ 42 | XMLParser_import_library = XMLParser_import_elementtree 43 | if Verbose_import_: 44 | print("running with cElementTree") 45 | except ImportError: 46 | try: 47 | # normal ElementTree install 48 | import elementtree.ElementTree as etree_ 49 | XMLParser_import_library = XMLParser_import_elementtree 50 | if Verbose_import_: 51 | print("running with ElementTree") 52 | except ImportError: 53 | raise ImportError("Failed to import ElementTree from any known place") 54 | 55 | def parsexml_(*args, **kwargs): 56 | if (XMLParser_import_library == XMLParser_import_lxml and 57 | 'parser' not in kwargs): 58 | # Use the lxml ElementTree compatible parser so that, e.g., 59 | # we ignore comments. 60 | kwargs['parser'] = etree_.ETCompatXMLParser() 61 | doc = etree_.parse(*args, **kwargs) 62 | return doc 63 | 64 | # 65 | # User methods 66 | # 67 | # Calls to the methods in these classes are generated by generateDS.py. 68 | # You can replace these methods by re-implementing the following class 69 | # in a module named generatedssuper.py. 70 | 71 | try: 72 | from generatedssuper import GeneratedsSuper 73 | except ImportError, exp: 74 | 75 | class GeneratedsSuper(object): 76 | def gds_format_string(self, input_data, input_name=''): 77 | return input_data 78 | def gds_validate_string(self, input_data, node, input_name=''): 79 | return input_data 80 | def gds_format_integer(self, input_data, input_name=''): 81 | return '%d' % input_data 82 | def gds_validate_integer(self, input_data, node, input_name=''): 83 | return input_data 84 | def gds_format_integer_list(self, input_data, input_name=''): 85 | return '%s' % input_data 86 | def gds_validate_integer_list(self, input_data, node, input_name=''): 87 | values = input_data.split() 88 | for value in values: 89 | try: 90 | fvalue = float(value) 91 | except (TypeError, ValueError), exp: 92 | raise_parse_error(node, 'Requires sequence of integers') 93 | return input_data 94 | def gds_format_float(self, input_data, input_name=''): 95 | return '%f' % input_data 96 | def gds_validate_float(self, input_data, node, input_name=''): 97 | return input_data 98 | def gds_format_float_list(self, input_data, input_name=''): 99 | return '%s' % input_data 100 | def gds_validate_float_list(self, input_data, node, input_name=''): 101 | values = input_data.split() 102 | for value in values: 103 | try: 104 | fvalue = float(value) 105 | except (TypeError, ValueError), exp: 106 | raise_parse_error(node, 'Requires sequence of floats') 107 | return input_data 108 | def gds_format_double(self, input_data, input_name=''): 109 | return '%e' % input_data 110 | def gds_validate_double(self, input_data, node, input_name=''): 111 | return input_data 112 | def gds_format_double_list(self, input_data, input_name=''): 113 | return '%s' % input_data 114 | def gds_validate_double_list(self, input_data, node, input_name=''): 115 | values = input_data.split() 116 | for value in values: 117 | try: 118 | fvalue = float(value) 119 | except (TypeError, ValueError), exp: 120 | raise_parse_error(node, 'Requires sequence of doubles') 121 | return input_data 122 | def gds_format_boolean(self, input_data, input_name=''): 123 | return '%s' % input_data 124 | def gds_validate_boolean(self, input_data, node, input_name=''): 125 | return input_data 126 | def gds_format_boolean_list(self, input_data, input_name=''): 127 | return '%s' % input_data 128 | def gds_validate_boolean_list(self, input_data, node, input_name=''): 129 | values = input_data.split() 130 | for value in values: 131 | if value not in ('true', '1', 'false', '0', ): 132 | raise_parse_error(node, 'Requires sequence of booleans ("true", "1", "false", "0")') 133 | return input_data 134 | def gds_str_lower(self, instring): 135 | return instring.lower() 136 | def get_path_(self, node): 137 | path_list = [] 138 | self.get_path_list_(node, path_list) 139 | path_list.reverse() 140 | path = '/'.join(path_list) 141 | return path 142 | Tag_strip_pattern_ = re_.compile(r'\{.*\}') 143 | def get_path_list_(self, node, path_list): 144 | if node is None: 145 | return 146 | tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag) 147 | if tag: 148 | path_list.append(tag) 149 | self.get_path_list_(node.getparent(), path_list) 150 | 151 | 152 | # 153 | # If you have installed IPython you can uncomment and use the following. 154 | # IPython is available from http://ipython.scipy.org/. 155 | # 156 | 157 | ## from IPython.Shell import IPShellEmbed 158 | ## args = '' 159 | ## ipshell = IPShellEmbed(args, 160 | ## banner = 'Dropping into IPython', 161 | ## exit_msg = 'Leaving Interpreter, back to program.') 162 | 163 | # Then use the following line where and when you want to drop into the 164 | # IPython shell: 165 | # ipshell(' -- Entering ipshell.\nHit Ctrl-D to exit') 166 | 167 | # 168 | # Globals 169 | # 170 | 171 | ExternalEncoding = 'ascii' 172 | Tag_pattern_ = re_.compile(r'({.*})?(.*)') 173 | STRING_CLEANUP_PAT = re_.compile(r"[\n\r\s]+") 174 | 175 | # 176 | # Support/utility functions. 177 | # 178 | 179 | def showIndent(outfile, level): 180 | for idx in range(level): 181 | outfile.write(' ') 182 | 183 | def quote_xml(inStr): 184 | if not inStr: 185 | return '' 186 | s1 = (isinstance(inStr, basestring) and inStr or 187 | '%s' % inStr) 188 | s1 = s1.replace('&', '&') 189 | s1 = s1.replace('<', '<') 190 | s1 = s1.replace('>', '>') 191 | return s1 192 | 193 | def quote_attrib(inStr): 194 | s1 = (isinstance(inStr, basestring) and inStr or 195 | '%s' % inStr) 196 | s1 = s1.replace('&', '&') 197 | s1 = s1.replace('<', '<') 198 | s1 = s1.replace('>', '>') 199 | if '"' in s1: 200 | if "'" in s1: 201 | s1 = '"%s"' % s1.replace('"', """) 202 | else: 203 | s1 = "'%s'" % s1 204 | else: 205 | s1 = '"%s"' % s1 206 | return s1 207 | 208 | def quote_python(inStr): 209 | s1 = inStr 210 | if s1.find("'") == -1: 211 | if s1.find('\n') == -1: 212 | return "'%s'" % s1 213 | else: 214 | return "'''%s'''" % s1 215 | else: 216 | if s1.find('"') != -1: 217 | s1 = s1.replace('"', '\\"') 218 | if s1.find('\n') == -1: 219 | return '"%s"' % s1 220 | else: 221 | return '"""%s"""' % s1 222 | 223 | 224 | def get_all_text_(node): 225 | if node.text is not None: 226 | text = node.text 227 | else: 228 | text = '' 229 | for child in node: 230 | if child.tail is not None: 231 | text += child.tail 232 | return text 233 | 234 | 235 | class GDSParseError(Exception): 236 | pass 237 | 238 | def raise_parse_error(node, msg): 239 | if XMLParser_import_library == XMLParser_import_lxml: 240 | msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, ) 241 | else: 242 | msg = '%s (element %s)' % (msg, node.tag, ) 243 | raise GDSParseError(msg) 244 | 245 | 246 | class MixedContainer: 247 | # Constants for category: 248 | CategoryNone = 0 249 | CategoryText = 1 250 | CategorySimple = 2 251 | CategoryComplex = 3 252 | # Constants for content_type: 253 | TypeNone = 0 254 | TypeText = 1 255 | TypeString = 2 256 | TypeInteger = 3 257 | TypeFloat = 4 258 | TypeDecimal = 5 259 | TypeDouble = 6 260 | TypeBoolean = 7 261 | def __init__(self, category, content_type, name, value): 262 | self.category = category 263 | self.content_type = content_type 264 | self.name = name 265 | self.value = value 266 | def getCategory(self): 267 | return self.category 268 | def getContenttype(self, content_type): 269 | return self.content_type 270 | def getValue(self): 271 | return self.value 272 | def getName(self): 273 | return self.name 274 | def export(self, outfile, level, name, namespace): 275 | if self.category == MixedContainer.CategoryText: 276 | # Prevent exporting empty content as empty lines. 277 | if self.value.strip(): 278 | outfile.write(self.value) 279 | elif self.category == MixedContainer.CategorySimple: 280 | self.exportSimple(outfile, level, name) 281 | else: # category == MixedContainer.CategoryComplex 282 | self.value.export(outfile, level, namespace,name) 283 | def exportSimple(self, outfile, level, name): 284 | if self.content_type == MixedContainer.TypeString: 285 | outfile.write('<%s>%s' % (self.name, self.value, self.name)) 286 | elif self.content_type == MixedContainer.TypeInteger or \ 287 | self.content_type == MixedContainer.TypeBoolean: 288 | outfile.write('<%s>%d' % (self.name, self.value, self.name)) 289 | elif self.content_type == MixedContainer.TypeFloat or \ 290 | self.content_type == MixedContainer.TypeDecimal: 291 | outfile.write('<%s>%f' % (self.name, self.value, self.name)) 292 | elif self.content_type == MixedContainer.TypeDouble: 293 | outfile.write('<%s>%g' % (self.name, self.value, self.name)) 294 | def exportLiteral(self, outfile, level, name): 295 | if self.category == MixedContainer.CategoryText: 296 | showIndent(outfile, level) 297 | outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ 298 | (self.category, self.content_type, self.name, self.value)) 299 | elif self.category == MixedContainer.CategorySimple: 300 | showIndent(outfile, level) 301 | outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ 302 | (self.category, self.content_type, self.name, self.value)) 303 | else: # category == MixedContainer.CategoryComplex 304 | showIndent(outfile, level) 305 | outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \ 306 | (self.category, self.content_type, self.name,)) 307 | self.value.exportLiteral(outfile, level + 1) 308 | showIndent(outfile, level) 309 | outfile.write(')\n') 310 | 311 | 312 | class MemberSpec_(object): 313 | def __init__(self, name='', data_type='', container=0): 314 | self.name = name 315 | self.data_type = data_type 316 | self.container = container 317 | def set_name(self, name): self.name = name 318 | def get_name(self): return self.name 319 | def set_data_type(self, data_type): self.data_type = data_type 320 | def get_data_type_chain(self): return self.data_type 321 | def get_data_type(self): 322 | if isinstance(self.data_type, list): 323 | if len(self.data_type) > 0: 324 | return self.data_type[-1] 325 | else: 326 | return 'xs:string' 327 | else: 328 | return self.data_type 329 | def set_container(self, container): self.container = container 330 | def get_container(self): return self.container 331 | 332 | def _cast(typ, value): 333 | if typ is None or value is None: 334 | return value 335 | return typ(value) 336 | 337 | # 338 | # Data representation classes. 339 | # 340 | 341 | class lexemeType(GeneratedsSuper): 342 | subclass = None 343 | superclass = None 344 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 345 | self.order = _cast(None, order) 346 | self.headword = _cast(bool, headword) 347 | self.breakBefore = _cast(bool, breakBefore) 348 | self.name = _cast(None, name) 349 | self.POS = _cast(None, POS) 350 | self.valueOf_ = valueOf_ 351 | def factory(*args_, **kwargs_): 352 | if lexemeType.subclass: 353 | return lexemeType.subclass(*args_, **kwargs_) 354 | else: 355 | return lexemeType(*args_, **kwargs_) 356 | factory = staticmethod(factory) 357 | def get_order(self): return self.order 358 | def set_order(self, order): self.order = order 359 | def get_headword(self): return self.headword 360 | def set_headword(self, headword): self.headword = headword 361 | def get_breakBefore(self): return self.breakBefore 362 | def set_breakBefore(self, breakBefore): self.breakBefore = breakBefore 363 | def get_name(self): return self.name 364 | def set_name(self, name): self.name = name 365 | def get_POS(self): return self.POS 366 | def set_POS(self, POS): self.POS = POS 367 | def get_valueOf_(self): return self.valueOf_ 368 | def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 369 | def export(self, outfile, level, namespace_='fn:', name_='lexemeType', namespacedef_=''): 370 | showIndent(outfile, level) 371 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 372 | self.exportAttributes(outfile, level, [], namespace_, name_='lexemeType') 373 | if self.hasContent_(): 374 | outfile.write('>') 375 | outfile.write(self.valueOf_) 376 | self.exportChildren(outfile, level + 1, namespace_, name_) 377 | outfile.write('\n' % (namespace_, name_)) 378 | else: 379 | outfile.write('/>\n') 380 | def exportAttributes(self, outfile, level, already_processed, namespace_='fn:', name_='lexemeType'): 381 | if self.order is not None and 'order' not in already_processed: 382 | already_processed.append('order') 383 | outfile.write(' order=%s' % (quote_attrib(self.order), )) 384 | if self.headword is not None and 'headword' not in already_processed: 385 | already_processed.append('headword') 386 | outfile.write(' headword="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.headword)), input_name='headword')) 387 | if self.breakBefore is not None and 'breakBefore' not in already_processed: 388 | already_processed.append('breakBefore') 389 | outfile.write(' breakBefore="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.breakBefore)), input_name='breakBefore')) 390 | if self.name is not None and 'name' not in already_processed: 391 | already_processed.append('name') 392 | outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), )) 393 | if self.POS is not None and 'POS' not in already_processed: 394 | already_processed.append('POS') 395 | outfile.write(' POS=%s' % (quote_attrib(self.POS), )) 396 | def exportChildren(self, outfile, level, namespace_='fn:', name_='lexemeType', fromsubclass_=False): 397 | pass 398 | def hasContent_(self): 399 | if ( 400 | self.valueOf_ 401 | ): 402 | return True 403 | else: 404 | return False 405 | def exportLiteral(self, outfile, level, name_='lexemeType'): 406 | level += 1 407 | self.exportLiteralAttributes(outfile, level, [], name_) 408 | if self.hasContent_(): 409 | self.exportLiteralChildren(outfile, level, name_) 410 | showIndent(outfile, level) 411 | outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) 412 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 413 | if self.order is not None and 'order' not in already_processed: 414 | already_processed.append('order') 415 | showIndent(outfile, level) 416 | outfile.write('order = %s,\n' % (self.order,)) 417 | if self.headword is not None and 'headword' not in already_processed: 418 | already_processed.append('headword') 419 | showIndent(outfile, level) 420 | outfile.write('headword = %s,\n' % (self.headword,)) 421 | if self.breakBefore is not None and 'breakBefore' not in already_processed: 422 | already_processed.append('breakBefore') 423 | showIndent(outfile, level) 424 | outfile.write('breakBefore = %s,\n' % (self.breakBefore,)) 425 | if self.name is not None and 'name' not in already_processed: 426 | already_processed.append('name') 427 | showIndent(outfile, level) 428 | outfile.write('name = "%s",\n' % (self.name,)) 429 | if self.POS is not None and 'POS' not in already_processed: 430 | already_processed.append('POS') 431 | showIndent(outfile, level) 432 | outfile.write('POS = %s,\n' % (self.POS,)) 433 | def exportLiteralChildren(self, outfile, level, name_): 434 | pass 435 | def build(self, node): 436 | self.buildAttributes(node, node.attrib, []) 437 | self.valueOf_ = get_all_text_(node) 438 | for child in node: 439 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 440 | self.buildChildren(child, node, nodeName_) 441 | def buildAttributes(self, node, attrs, already_processed): 442 | value = attrs.get('order') 443 | if value is not None and 'order' not in already_processed: 444 | already_processed.append('order') 445 | self.order = value 446 | value = attrs.get('headword') 447 | if value is not None and 'headword' not in already_processed: 448 | already_processed.append('headword') 449 | if value in ('true', '1'): 450 | self.headword = True 451 | elif value in ('false', '0'): 452 | self.headword = False 453 | else: 454 | raise_parse_error(node, 'Bad boolean attribute') 455 | value = attrs.get('breakBefore') 456 | if value is not None and 'breakBefore' not in already_processed: 457 | already_processed.append('breakBefore') 458 | if value in ('true', '1'): 459 | self.breakBefore = True 460 | elif value in ('false', '0'): 461 | self.breakBefore = False 462 | else: 463 | raise_parse_error(node, 'Bad boolean attribute') 464 | value = attrs.get('name') 465 | if value is not None and 'name' not in already_processed: 466 | already_processed.append('name') 467 | self.name = value 468 | value = attrs.get('POS') 469 | if value is not None and 'POS' not in already_processed: 470 | already_processed.append('POS') 471 | self.POS = value 472 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 473 | pass 474 | # end class lexemeType 475 | 476 | 477 | class semTypeRefType(GeneratedsSuper): 478 | subclass = None 479 | superclass = None 480 | def __init__(self, ID=None, name=None, valueOf_=None): 481 | self.ID = _cast(None, ID) 482 | self.name = _cast(None, name) 483 | self.valueOf_ = valueOf_ 484 | def factory(*args_, **kwargs_): 485 | if semTypeRefType.subclass: 486 | return semTypeRefType.subclass(*args_, **kwargs_) 487 | else: 488 | return semTypeRefType(*args_, **kwargs_) 489 | factory = staticmethod(factory) 490 | def get_ID(self): return self.ID 491 | def set_ID(self, ID): self.ID = ID 492 | def get_name(self): return self.name 493 | def set_name(self, name): self.name = name 494 | def get_valueOf_(self): return self.valueOf_ 495 | def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 496 | def export(self, outfile, level, namespace_='fn:', name_='semTypeRefType', namespacedef_=''): 497 | showIndent(outfile, level) 498 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 499 | self.exportAttributes(outfile, level, [], namespace_, name_='semTypeRefType') 500 | if self.hasContent_(): 501 | outfile.write('>') 502 | outfile.write(self.valueOf_) 503 | self.exportChildren(outfile, level + 1, namespace_, name_) 504 | outfile.write('\n' % (namespace_, name_)) 505 | else: 506 | outfile.write('/>\n') 507 | def exportAttributes(self, outfile, level, already_processed, namespace_='fn:', name_='semTypeRefType'): 508 | if self.ID is not None and 'ID' not in already_processed: 509 | already_processed.append('ID') 510 | outfile.write(' ID=%s' % (quote_attrib(self.ID), )) 511 | if self.name is not None and 'name' not in already_processed: 512 | already_processed.append('name') 513 | outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), )) 514 | def exportChildren(self, outfile, level, namespace_='fn:', name_='semTypeRefType', fromsubclass_=False): 515 | pass 516 | def hasContent_(self): 517 | if ( 518 | self.valueOf_ 519 | ): 520 | return True 521 | else: 522 | return False 523 | def exportLiteral(self, outfile, level, name_='semTypeRefType'): 524 | level += 1 525 | self.exportLiteralAttributes(outfile, level, [], name_) 526 | if self.hasContent_(): 527 | self.exportLiteralChildren(outfile, level, name_) 528 | showIndent(outfile, level) 529 | outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) 530 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 531 | if self.ID is not None and 'ID' not in already_processed: 532 | already_processed.append('ID') 533 | showIndent(outfile, level) 534 | outfile.write('ID = %s,\n' % (self.ID,)) 535 | if self.name is not None and 'name' not in already_processed: 536 | already_processed.append('name') 537 | showIndent(outfile, level) 538 | outfile.write('name = "%s",\n' % (self.name,)) 539 | def exportLiteralChildren(self, outfile, level, name_): 540 | pass 541 | def build(self, node): 542 | self.buildAttributes(node, node.attrib, []) 543 | self.valueOf_ = get_all_text_(node) 544 | for child in node: 545 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 546 | self.buildChildren(child, node, nodeName_) 547 | def buildAttributes(self, node, attrs, already_processed): 548 | value = attrs.get('ID') 549 | if value is not None and 'ID' not in already_processed: 550 | already_processed.append('ID') 551 | self.ID = value 552 | value = attrs.get('name') 553 | if value is not None and 'name' not in already_processed: 554 | already_processed.append('name') 555 | self.name = value 556 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 557 | pass 558 | # end class semTypeRefType 559 | 560 | 561 | USAGE_TEXT = """ 562 | Usage: python .py [ -s ] 563 | """ 564 | 565 | def usage(): 566 | print USAGE_TEXT 567 | sys.exit(1) 568 | 569 | 570 | def get_root_tag(node): 571 | tag = Tag_pattern_.match(node.tag).groups()[-1] 572 | rootClass = globals().get(tag) 573 | return tag, rootClass 574 | 575 | 576 | def parse(inFileName): 577 | doc = parsexml_(inFileName) 578 | rootNode = doc.getroot() 579 | rootTag, rootClass = get_root_tag(rootNode) 580 | if rootClass is None: 581 | rootTag = 'lexemeType' 582 | rootClass = lexemeType 583 | rootObj = rootClass.factory() 584 | rootObj.build(rootNode) 585 | # Enable Python to collect the space used by the DOM. 586 | doc = None 587 | sys.stdout.write('\n') 588 | rootObj.export(sys.stdout, 0, name_=rootTag, 589 | namespacedef_='') 590 | return rootObj 591 | 592 | 593 | def parseString(inString): 594 | from StringIO import StringIO 595 | doc = parsexml_(StringIO(inString)) 596 | rootNode = doc.getroot() 597 | rootTag, rootClass = get_root_tag(rootNode) 598 | if rootClass is None: 599 | rootTag = 'lexemeType' 600 | rootClass = lexemeType 601 | rootObj = rootClass.factory() 602 | rootObj.build(rootNode) 603 | # Enable Python to collect the space used by the DOM. 604 | doc = None 605 | sys.stdout.write('\n') 606 | rootObj.export(sys.stdout, 0, name_="lexemeType", 607 | namespacedef_='') 608 | return rootObj 609 | 610 | 611 | def parseLiteral(inFileName): 612 | doc = parsexml_(inFileName) 613 | rootNode = doc.getroot() 614 | rootTag, rootClass = get_root_tag(rootNode) 615 | if rootClass is None: 616 | rootTag = 'lexemeType' 617 | rootClass = lexemeType 618 | rootObj = rootClass.factory() 619 | rootObj.build(rootNode) 620 | # Enable Python to collect the space used by the DOM. 621 | doc = None 622 | sys.stdout.write('#from commonTypes import *\n\n') 623 | sys.stdout.write('import commonTypes as model_\n\n') 624 | sys.stdout.write('rootObj = model_.rootTag(\n') 625 | rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) 626 | sys.stdout.write(')\n') 627 | return rootObj 628 | 629 | 630 | def main(): 631 | args = sys.argv[1:] 632 | if len(args) == 1: 633 | parse(args[0]) 634 | else: 635 | usage() 636 | 637 | 638 | if __name__ == '__main__': 639 | #import pdb; pdb.set_trace() 640 | main() 641 | 642 | 643 | __all__ = [ 644 | "lexemeType", 645 | "semTypeRefType" 646 | ] 647 | -------------------------------------------------------------------------------- /1.5/commonTypesSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 15:55:47 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class lexemeTypeSub(supermod.lexemeType): 74 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 75 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 76 | supermod.lexemeType.subclass = lexemeTypeSub 77 | # end class lexemeTypeSub 78 | 79 | 80 | class semTypeRefTypeSub(supermod.semTypeRefType): 81 | def __init__(self, ID=None, name=None, valueOf_=None): 82 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 83 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 84 | # end class semTypeRefTypeSub 85 | 86 | 87 | 88 | def get_root_tag(node): 89 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 90 | rootClass = None 91 | if hasattr(supermod, tag): 92 | rootClass = getattr(supermod, tag) 93 | return tag, rootClass 94 | 95 | 96 | def parse(inFilename): 97 | doc = parsexml_(inFilename) 98 | rootNode = doc.getroot() 99 | rootTag, rootClass = get_root_tag(rootNode) 100 | if rootClass is None: 101 | rootTag = 'lexemeType' 102 | rootClass = supermod.lexemeType 103 | rootObj = rootClass.factory() 104 | rootObj.build(rootNode) 105 | # Enable Python to collect the space used by the DOM. 106 | doc = None 107 | sys.stdout.write('\n') 108 | rootObj.export(sys.stdout, 0, name_=rootTag, 109 | namespacedef_='') 110 | doc = None 111 | return rootObj 112 | 113 | 114 | def parseString(inString): 115 | from StringIO import StringIO 116 | doc = parsexml_(StringIO(inString)) 117 | rootNode = doc.getroot() 118 | rootTag, rootClass = get_root_tag(rootNode) 119 | if rootClass is None: 120 | rootTag = 'lexemeType' 121 | rootClass = supermod.lexemeType 122 | rootObj = rootClass.factory() 123 | rootObj.build(rootNode) 124 | # Enable Python to collect the space used by the DOM. 125 | doc = None 126 | sys.stdout.write('\n') 127 | rootObj.export(sys.stdout, 0, name_=rootTag, 128 | namespacedef_='') 129 | return rootObj 130 | 131 | 132 | def parseLiteral(inFilename): 133 | doc = parsexml_(inFilename) 134 | rootNode = doc.getroot() 135 | rootTag, rootClass = get_root_tag(rootNode) 136 | if rootClass is None: 137 | rootTag = 'lexemeType' 138 | rootClass = supermod.lexemeType 139 | rootObj = rootClass.factory() 140 | rootObj.build(rootNode) 141 | # Enable Python to collect the space used by the DOM. 142 | doc = None 143 | sys.stdout.write('#from ??? import *\n\n') 144 | sys.stdout.write('import ??? as model_\n\n') 145 | sys.stdout.write('rootObj = model_.lexemeType(\n') 146 | rootObj.exportLiteral(sys.stdout, 0, name_="lexemeType") 147 | sys.stdout.write(')\n') 148 | return rootObj 149 | 150 | 151 | USAGE_TEXT = """ 152 | Usage: python ???.py 153 | """ 154 | 155 | def usage(): 156 | print USAGE_TEXT 157 | sys.exit(1) 158 | 159 | 160 | def main(): 161 | args = sys.argv[1:] 162 | if len(args) != 1: 163 | usage() 164 | infilename = args[0] 165 | root = parse(infilename) 166 | 167 | 168 | if __name__ == '__main__': 169 | #import pdb; pdb.set_trace() 170 | main() 171 | 172 | 173 | -------------------------------------------------------------------------------- /1.5/frameIndex.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Generated Fri Apr 15 16:00:42 2011 by generateDS.py version 2.4c. 6 | # 7 | 8 | import sys 9 | import getopt 10 | import re as re_ 11 | 12 | etree_ = None 13 | Verbose_import_ = False 14 | ( XMLParser_import_none, XMLParser_import_lxml, 15 | XMLParser_import_elementtree 16 | ) = range(3) 17 | XMLParser_import_library = None 18 | try: 19 | # lxml 20 | from lxml import etree as etree_ 21 | XMLParser_import_library = XMLParser_import_lxml 22 | if Verbose_import_: 23 | print("running with lxml.etree") 24 | except ImportError: 25 | try: 26 | # cElementTree from Python 2.5+ 27 | import xml.etree.cElementTree as etree_ 28 | XMLParser_import_library = XMLParser_import_elementtree 29 | if Verbose_import_: 30 | print("running with cElementTree on Python 2.5+") 31 | except ImportError: 32 | try: 33 | # ElementTree from Python 2.5+ 34 | import xml.etree.ElementTree as etree_ 35 | XMLParser_import_library = XMLParser_import_elementtree 36 | if Verbose_import_: 37 | print("running with ElementTree on Python 2.5+") 38 | except ImportError: 39 | try: 40 | # normal cElementTree install 41 | import cElementTree as etree_ 42 | XMLParser_import_library = XMLParser_import_elementtree 43 | if Verbose_import_: 44 | print("running with cElementTree") 45 | except ImportError: 46 | try: 47 | # normal ElementTree install 48 | import elementtree.ElementTree as etree_ 49 | XMLParser_import_library = XMLParser_import_elementtree 50 | if Verbose_import_: 51 | print("running with ElementTree") 52 | except ImportError: 53 | raise ImportError("Failed to import ElementTree from any known place") 54 | 55 | def parsexml_(*args, **kwargs): 56 | if (XMLParser_import_library == XMLParser_import_lxml and 57 | 'parser' not in kwargs): 58 | # Use the lxml ElementTree compatible parser so that, e.g., 59 | # we ignore comments. 60 | kwargs['parser'] = etree_.ETCompatXMLParser() 61 | doc = etree_.parse(*args, **kwargs) 62 | return doc 63 | 64 | # 65 | # User methods 66 | # 67 | # Calls to the methods in these classes are generated by generateDS.py. 68 | # You can replace these methods by re-implementing the following class 69 | # in a module named generatedssuper.py. 70 | 71 | try: 72 | from generatedssuper import GeneratedsSuper 73 | except ImportError, exp: 74 | 75 | class GeneratedsSuper(object): 76 | def gds_format_string(self, input_data, input_name=''): 77 | return input_data 78 | def gds_validate_string(self, input_data, node, input_name=''): 79 | return input_data 80 | def gds_format_integer(self, input_data, input_name=''): 81 | return '%d' % input_data 82 | def gds_validate_integer(self, input_data, node, input_name=''): 83 | return input_data 84 | def gds_format_integer_list(self, input_data, input_name=''): 85 | return '%s' % input_data 86 | def gds_validate_integer_list(self, input_data, node, input_name=''): 87 | values = input_data.split() 88 | for value in values: 89 | try: 90 | fvalue = float(value) 91 | except (TypeError, ValueError), exp: 92 | raise_parse_error(node, 'Requires sequence of integers') 93 | return input_data 94 | def gds_format_float(self, input_data, input_name=''): 95 | return '%f' % input_data 96 | def gds_validate_float(self, input_data, node, input_name=''): 97 | return input_data 98 | def gds_format_float_list(self, input_data, input_name=''): 99 | return '%s' % input_data 100 | def gds_validate_float_list(self, input_data, node, input_name=''): 101 | values = input_data.split() 102 | for value in values: 103 | try: 104 | fvalue = float(value) 105 | except (TypeError, ValueError), exp: 106 | raise_parse_error(node, 'Requires sequence of floats') 107 | return input_data 108 | def gds_format_double(self, input_data, input_name=''): 109 | return '%e' % input_data 110 | def gds_validate_double(self, input_data, node, input_name=''): 111 | return input_data 112 | def gds_format_double_list(self, input_data, input_name=''): 113 | return '%s' % input_data 114 | def gds_validate_double_list(self, input_data, node, input_name=''): 115 | values = input_data.split() 116 | for value in values: 117 | try: 118 | fvalue = float(value) 119 | except (TypeError, ValueError), exp: 120 | raise_parse_error(node, 'Requires sequence of doubles') 121 | return input_data 122 | def gds_format_boolean(self, input_data, input_name=''): 123 | return '%s' % input_data 124 | def gds_validate_boolean(self, input_data, node, input_name=''): 125 | return input_data 126 | def gds_format_boolean_list(self, input_data, input_name=''): 127 | return '%s' % input_data 128 | def gds_validate_boolean_list(self, input_data, node, input_name=''): 129 | values = input_data.split() 130 | for value in values: 131 | if value not in ('true', '1', 'false', '0', ): 132 | raise_parse_error(node, 'Requires sequence of booleans ("true", "1", "false", "0")') 133 | return input_data 134 | def gds_str_lower(self, instring): 135 | return instring.lower() 136 | def get_path_(self, node): 137 | path_list = [] 138 | self.get_path_list_(node, path_list) 139 | path_list.reverse() 140 | path = '/'.join(path_list) 141 | return path 142 | Tag_strip_pattern_ = re_.compile(r'\{.*\}') 143 | def get_path_list_(self, node, path_list): 144 | if node is None: 145 | return 146 | tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag) 147 | if tag: 148 | path_list.append(tag) 149 | self.get_path_list_(node.getparent(), path_list) 150 | 151 | 152 | # 153 | # If you have installed IPython you can uncomment and use the following. 154 | # IPython is available from http://ipython.scipy.org/. 155 | # 156 | 157 | ## from IPython.Shell import IPShellEmbed 158 | ## args = '' 159 | ## ipshell = IPShellEmbed(args, 160 | ## banner = 'Dropping into IPython', 161 | ## exit_msg = 'Leaving Interpreter, back to program.') 162 | 163 | # Then use the following line where and when you want to drop into the 164 | # IPython shell: 165 | # ipshell(' -- Entering ipshell.\nHit Ctrl-D to exit') 166 | 167 | # 168 | # Globals 169 | # 170 | 171 | ExternalEncoding = 'ascii' 172 | Tag_pattern_ = re_.compile(r'({.*})?(.*)') 173 | STRING_CLEANUP_PAT = re_.compile(r"[\n\r\s]+") 174 | 175 | # 176 | # Support/utility functions. 177 | # 178 | 179 | def showIndent(outfile, level): 180 | for idx in range(level): 181 | outfile.write(' ') 182 | 183 | def quote_xml(inStr): 184 | if not inStr: 185 | return '' 186 | s1 = (isinstance(inStr, basestring) and inStr or 187 | '%s' % inStr) 188 | s1 = s1.replace('&', '&') 189 | s1 = s1.replace('<', '<') 190 | s1 = s1.replace('>', '>') 191 | return s1 192 | 193 | def quote_attrib(inStr): 194 | s1 = (isinstance(inStr, basestring) and inStr or 195 | '%s' % inStr) 196 | s1 = s1.replace('&', '&') 197 | s1 = s1.replace('<', '<') 198 | s1 = s1.replace('>', '>') 199 | if '"' in s1: 200 | if "'" in s1: 201 | s1 = '"%s"' % s1.replace('"', """) 202 | else: 203 | s1 = "'%s'" % s1 204 | else: 205 | s1 = '"%s"' % s1 206 | return s1 207 | 208 | def quote_python(inStr): 209 | s1 = inStr 210 | if s1.find("'") == -1: 211 | if s1.find('\n') == -1: 212 | return "'%s'" % s1 213 | else: 214 | return "'''%s'''" % s1 215 | else: 216 | if s1.find('"') != -1: 217 | s1 = s1.replace('"', '\\"') 218 | if s1.find('\n') == -1: 219 | return '"%s"' % s1 220 | else: 221 | return '"""%s"""' % s1 222 | 223 | 224 | def get_all_text_(node): 225 | if node.text is not None: 226 | text = node.text 227 | else: 228 | text = '' 229 | for child in node: 230 | if child.tail is not None: 231 | text += child.tail 232 | return text 233 | 234 | 235 | class GDSParseError(Exception): 236 | pass 237 | 238 | def raise_parse_error(node, msg): 239 | if XMLParser_import_library == XMLParser_import_lxml: 240 | msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, ) 241 | else: 242 | msg = '%s (element %s)' % (msg, node.tag, ) 243 | raise GDSParseError(msg) 244 | 245 | 246 | class MixedContainer: 247 | # Constants for category: 248 | CategoryNone = 0 249 | CategoryText = 1 250 | CategorySimple = 2 251 | CategoryComplex = 3 252 | # Constants for content_type: 253 | TypeNone = 0 254 | TypeText = 1 255 | TypeString = 2 256 | TypeInteger = 3 257 | TypeFloat = 4 258 | TypeDecimal = 5 259 | TypeDouble = 6 260 | TypeBoolean = 7 261 | def __init__(self, category, content_type, name, value): 262 | self.category = category 263 | self.content_type = content_type 264 | self.name = name 265 | self.value = value 266 | def getCategory(self): 267 | return self.category 268 | def getContenttype(self, content_type): 269 | return self.content_type 270 | def getValue(self): 271 | return self.value 272 | def getName(self): 273 | return self.name 274 | def export(self, outfile, level, name, namespace): 275 | if self.category == MixedContainer.CategoryText: 276 | # Prevent exporting empty content as empty lines. 277 | if self.value.strip(): 278 | outfile.write(self.value) 279 | elif self.category == MixedContainer.CategorySimple: 280 | self.exportSimple(outfile, level, name) 281 | else: # category == MixedContainer.CategoryComplex 282 | self.value.export(outfile, level, namespace,name) 283 | def exportSimple(self, outfile, level, name): 284 | if self.content_type == MixedContainer.TypeString: 285 | outfile.write('<%s>%s' % (self.name, self.value, self.name)) 286 | elif self.content_type == MixedContainer.TypeInteger or \ 287 | self.content_type == MixedContainer.TypeBoolean: 288 | outfile.write('<%s>%d' % (self.name, self.value, self.name)) 289 | elif self.content_type == MixedContainer.TypeFloat or \ 290 | self.content_type == MixedContainer.TypeDecimal: 291 | outfile.write('<%s>%f' % (self.name, self.value, self.name)) 292 | elif self.content_type == MixedContainer.TypeDouble: 293 | outfile.write('<%s>%g' % (self.name, self.value, self.name)) 294 | def exportLiteral(self, outfile, level, name): 295 | if self.category == MixedContainer.CategoryText: 296 | showIndent(outfile, level) 297 | outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ 298 | (self.category, self.content_type, self.name, self.value)) 299 | elif self.category == MixedContainer.CategorySimple: 300 | showIndent(outfile, level) 301 | outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ 302 | (self.category, self.content_type, self.name, self.value)) 303 | else: # category == MixedContainer.CategoryComplex 304 | showIndent(outfile, level) 305 | outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \ 306 | (self.category, self.content_type, self.name,)) 307 | self.value.exportLiteral(outfile, level + 1) 308 | showIndent(outfile, level) 309 | outfile.write(')\n') 310 | 311 | 312 | class MemberSpec_(object): 313 | def __init__(self, name='', data_type='', container=0): 314 | self.name = name 315 | self.data_type = data_type 316 | self.container = container 317 | def set_name(self, name): self.name = name 318 | def get_name(self): return self.name 319 | def set_data_type(self, data_type): self.data_type = data_type 320 | def get_data_type_chain(self): return self.data_type 321 | def get_data_type(self): 322 | if isinstance(self.data_type, list): 323 | if len(self.data_type) > 0: 324 | return self.data_type[-1] 325 | else: 326 | return 'xs:string' 327 | else: 328 | return self.data_type 329 | def set_container(self, container): self.container = container 330 | def get_container(self): return self.container 331 | 332 | def _cast(typ, value): 333 | if typ is None or value is None: 334 | return value 335 | return typ(value) 336 | 337 | # 338 | # Data representation classes. 339 | # 340 | 341 | class frameIndex(GeneratedsSuper): 342 | subclass = None 343 | superclass = None 344 | def __init__(self, frame=None): 345 | if frame is None: 346 | self.frame = [] 347 | else: 348 | self.frame = frame 349 | def factory(*args_, **kwargs_): 350 | if frameIndex.subclass: 351 | return frameIndex.subclass(*args_, **kwargs_) 352 | else: 353 | return frameIndex(*args_, **kwargs_) 354 | factory = staticmethod(factory) 355 | def get_frame(self): return self.frame 356 | def set_frame(self, frame): self.frame = frame 357 | def add_frame(self, value): self.frame.append(value) 358 | def insert_frame(self, index, value): self.frame[index] = value 359 | def export(self, outfile, level, namespace_='fn:', name_='frameIndex', namespacedef_=''): 360 | showIndent(outfile, level) 361 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 362 | self.exportAttributes(outfile, level, [], namespace_, name_='frameIndex') 363 | if self.hasContent_(): 364 | outfile.write('>\n') 365 | self.exportChildren(outfile, level + 1, namespace_, name_) 366 | showIndent(outfile, level) 367 | outfile.write('\n' % (namespace_, name_)) 368 | else: 369 | outfile.write('/>\n') 370 | def exportAttributes(self, outfile, level, already_processed, namespace_='fn:', name_='frameIndex'): 371 | pass 372 | def exportChildren(self, outfile, level, namespace_='fn:', name_='frameIndex', fromsubclass_=False): 373 | for frame_ in self.frame: 374 | frame_.export(outfile, level, namespace_, name_='frame') 375 | def hasContent_(self): 376 | if ( 377 | self.frame 378 | ): 379 | return True 380 | else: 381 | return False 382 | def exportLiteral(self, outfile, level, name_='frameIndex'): 383 | level += 1 384 | self.exportLiteralAttributes(outfile, level, [], name_) 385 | if self.hasContent_(): 386 | self.exportLiteralChildren(outfile, level, name_) 387 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 388 | pass 389 | def exportLiteralChildren(self, outfile, level, name_): 390 | showIndent(outfile, level) 391 | outfile.write('frame=[\n') 392 | level += 1 393 | for frame_ in self.frame: 394 | showIndent(outfile, level) 395 | outfile.write('model_.frame(\n') 396 | frame_.exportLiteral(outfile, level) 397 | showIndent(outfile, level) 398 | outfile.write('),\n') 399 | level -= 1 400 | showIndent(outfile, level) 401 | outfile.write('],\n') 402 | def build(self, node): 403 | self.buildAttributes(node, node.attrib, []) 404 | for child in node: 405 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 406 | self.buildChildren(child, node, nodeName_) 407 | def buildAttributes(self, node, attrs, already_processed): 408 | pass 409 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 410 | if nodeName_ == 'frame': 411 | obj_ = frame.factory() 412 | obj_.build(child_) 413 | self.frame.append(obj_) 414 | # end class frameIndex 415 | 416 | 417 | class frame(GeneratedsSuper): 418 | subclass = None 419 | superclass = None 420 | def __init__(self, mDate=None, name=None, ID=None, valueOf_=None): 421 | self.mDate = _cast(None, mDate) 422 | self.name = _cast(None, name) 423 | self.ID = _cast(int, ID) 424 | self.valueOf_ = valueOf_ 425 | def factory(*args_, **kwargs_): 426 | if frame.subclass: 427 | return frame.subclass(*args_, **kwargs_) 428 | else: 429 | return frame(*args_, **kwargs_) 430 | factory = staticmethod(factory) 431 | def get_mDate(self): return self.mDate 432 | def set_mDate(self, mDate): self.mDate = mDate 433 | def get_name(self): return self.name 434 | def set_name(self, name): self.name = name 435 | def get_ID(self): return self.ID 436 | def set_ID(self, ID): self.ID = ID 437 | def get_valueOf_(self): return self.valueOf_ 438 | def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 439 | def export(self, outfile, level, namespace_='fn:', name_='frame', namespacedef_=''): 440 | showIndent(outfile, level) 441 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 442 | self.exportAttributes(outfile, level, [], namespace_, name_='frame') 443 | if self.hasContent_(): 444 | outfile.write('>') 445 | outfile.write(self.valueOf_) 446 | self.exportChildren(outfile, level + 1, namespace_, name_) 447 | outfile.write('\n' % (namespace_, name_)) 448 | else: 449 | outfile.write('/>\n') 450 | def exportAttributes(self, outfile, level, already_processed, namespace_='fn:', name_='frame'): 451 | if self.mDate is not None and 'mDate' not in already_processed: 452 | already_processed.append('mDate') 453 | outfile.write(' mDate=%s' % (quote_attrib(self.mDate), )) 454 | if self.name is not None and 'name' not in already_processed: 455 | already_processed.append('name') 456 | outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), )) 457 | if self.ID is not None and 'ID' not in already_processed: 458 | already_processed.append('ID') 459 | outfile.write(' ID="%s"' % self.gds_format_integer(self.ID, input_name='ID')) 460 | def exportChildren(self, outfile, level, namespace_='fn:', name_='frame', fromsubclass_=False): 461 | pass 462 | def hasContent_(self): 463 | if ( 464 | self.valueOf_ 465 | ): 466 | return True 467 | else: 468 | return False 469 | def exportLiteral(self, outfile, level, name_='frame'): 470 | level += 1 471 | self.exportLiteralAttributes(outfile, level, [], name_) 472 | if self.hasContent_(): 473 | self.exportLiteralChildren(outfile, level, name_) 474 | showIndent(outfile, level) 475 | outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) 476 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 477 | if self.mDate is not None and 'mDate' not in already_processed: 478 | already_processed.append('mDate') 479 | showIndent(outfile, level) 480 | outfile.write('mDate = %s,\n' % (self.mDate,)) 481 | if self.name is not None and 'name' not in already_processed: 482 | already_processed.append('name') 483 | showIndent(outfile, level) 484 | outfile.write('name = "%s",\n' % (self.name,)) 485 | if self.ID is not None and 'ID' not in already_processed: 486 | already_processed.append('ID') 487 | showIndent(outfile, level) 488 | outfile.write('ID = %d,\n' % (self.ID,)) 489 | def exportLiteralChildren(self, outfile, level, name_): 490 | pass 491 | def build(self, node): 492 | self.buildAttributes(node, node.attrib, []) 493 | self.valueOf_ = get_all_text_(node) 494 | for child in node: 495 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 496 | self.buildChildren(child, node, nodeName_) 497 | def buildAttributes(self, node, attrs, already_processed): 498 | value = attrs.get('mDate') 499 | if value is not None and 'mDate' not in already_processed: 500 | already_processed.append('mDate') 501 | self.mDate = value 502 | value = attrs.get('name') 503 | if value is not None and 'name' not in already_processed: 504 | already_processed.append('name') 505 | self.name = value 506 | value = attrs.get('ID') 507 | if value is not None and 'ID' not in already_processed: 508 | already_processed.append('ID') 509 | try: 510 | self.ID = int(value) 511 | except ValueError, exp: 512 | raise_parse_error(node, 'Bad integer attribute: %s' % exp) 513 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 514 | pass 515 | # end class frame 516 | 517 | 518 | class lexemeType(GeneratedsSuper): 519 | subclass = None 520 | superclass = None 521 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 522 | self.order = _cast(None, order) 523 | self.headword = _cast(bool, headword) 524 | self.breakBefore = _cast(bool, breakBefore) 525 | self.name = _cast(None, name) 526 | self.POS = _cast(None, POS) 527 | self.valueOf_ = valueOf_ 528 | def factory(*args_, **kwargs_): 529 | if lexemeType.subclass: 530 | return lexemeType.subclass(*args_, **kwargs_) 531 | else: 532 | return lexemeType(*args_, **kwargs_) 533 | factory = staticmethod(factory) 534 | def get_order(self): return self.order 535 | def set_order(self, order): self.order = order 536 | def get_headword(self): return self.headword 537 | def set_headword(self, headword): self.headword = headword 538 | def get_breakBefore(self): return self.breakBefore 539 | def set_breakBefore(self, breakBefore): self.breakBefore = breakBefore 540 | def get_name(self): return self.name 541 | def set_name(self, name): self.name = name 542 | def get_POS(self): return self.POS 543 | def set_POS(self, POS): self.POS = POS 544 | def get_valueOf_(self): return self.valueOf_ 545 | def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 546 | def export(self, outfile, level, namespace_='fn:', name_='lexemeType', namespacedef_=''): 547 | showIndent(outfile, level) 548 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 549 | self.exportAttributes(outfile, level, [], namespace_, name_='lexemeType') 550 | if self.hasContent_(): 551 | outfile.write('>') 552 | outfile.write(self.valueOf_) 553 | self.exportChildren(outfile, level + 1, namespace_, name_) 554 | outfile.write('\n' % (namespace_, name_)) 555 | else: 556 | outfile.write('/>\n') 557 | def exportAttributes(self, outfile, level, already_processed, namespace_='fn:', name_='lexemeType'): 558 | if self.order is not None and 'order' not in already_processed: 559 | already_processed.append('order') 560 | outfile.write(' order=%s' % (quote_attrib(self.order), )) 561 | if self.headword is not None and 'headword' not in already_processed: 562 | already_processed.append('headword') 563 | outfile.write(' headword="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.headword)), input_name='headword')) 564 | if self.breakBefore is not None and 'breakBefore' not in already_processed: 565 | already_processed.append('breakBefore') 566 | outfile.write(' breakBefore="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.breakBefore)), input_name='breakBefore')) 567 | if self.name is not None and 'name' not in already_processed: 568 | already_processed.append('name') 569 | outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), )) 570 | if self.POS is not None and 'POS' not in already_processed: 571 | already_processed.append('POS') 572 | outfile.write(' POS=%s' % (quote_attrib(self.POS), )) 573 | def exportChildren(self, outfile, level, namespace_='fn:', name_='lexemeType', fromsubclass_=False): 574 | pass 575 | def hasContent_(self): 576 | if ( 577 | self.valueOf_ 578 | ): 579 | return True 580 | else: 581 | return False 582 | def exportLiteral(self, outfile, level, name_='lexemeType'): 583 | level += 1 584 | self.exportLiteralAttributes(outfile, level, [], name_) 585 | if self.hasContent_(): 586 | self.exportLiteralChildren(outfile, level, name_) 587 | showIndent(outfile, level) 588 | outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) 589 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 590 | if self.order is not None and 'order' not in already_processed: 591 | already_processed.append('order') 592 | showIndent(outfile, level) 593 | outfile.write('order = %s,\n' % (self.order,)) 594 | if self.headword is not None and 'headword' not in already_processed: 595 | already_processed.append('headword') 596 | showIndent(outfile, level) 597 | outfile.write('headword = %s,\n' % (self.headword,)) 598 | if self.breakBefore is not None and 'breakBefore' not in already_processed: 599 | already_processed.append('breakBefore') 600 | showIndent(outfile, level) 601 | outfile.write('breakBefore = %s,\n' % (self.breakBefore,)) 602 | if self.name is not None and 'name' not in already_processed: 603 | already_processed.append('name') 604 | showIndent(outfile, level) 605 | outfile.write('name = "%s",\n' % (self.name,)) 606 | if self.POS is not None and 'POS' not in already_processed: 607 | already_processed.append('POS') 608 | showIndent(outfile, level) 609 | outfile.write('POS = %s,\n' % (self.POS,)) 610 | def exportLiteralChildren(self, outfile, level, name_): 611 | pass 612 | def build(self, node): 613 | self.buildAttributes(node, node.attrib, []) 614 | self.valueOf_ = get_all_text_(node) 615 | for child in node: 616 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 617 | self.buildChildren(child, node, nodeName_) 618 | def buildAttributes(self, node, attrs, already_processed): 619 | value = attrs.get('order') 620 | if value is not None and 'order' not in already_processed: 621 | already_processed.append('order') 622 | self.order = value 623 | value = attrs.get('headword') 624 | if value is not None and 'headword' not in already_processed: 625 | already_processed.append('headword') 626 | if value in ('true', '1'): 627 | self.headword = True 628 | elif value in ('false', '0'): 629 | self.headword = False 630 | else: 631 | raise_parse_error(node, 'Bad boolean attribute') 632 | value = attrs.get('breakBefore') 633 | if value is not None and 'breakBefore' not in already_processed: 634 | already_processed.append('breakBefore') 635 | if value in ('true', '1'): 636 | self.breakBefore = True 637 | elif value in ('false', '0'): 638 | self.breakBefore = False 639 | else: 640 | raise_parse_error(node, 'Bad boolean attribute') 641 | value = attrs.get('name') 642 | if value is not None and 'name' not in already_processed: 643 | already_processed.append('name') 644 | self.name = value 645 | value = attrs.get('POS') 646 | if value is not None and 'POS' not in already_processed: 647 | already_processed.append('POS') 648 | self.POS = value 649 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 650 | pass 651 | # end class lexemeType 652 | 653 | 654 | class semTypeRefType(GeneratedsSuper): 655 | subclass = None 656 | superclass = None 657 | def __init__(self, ID=None, name=None, valueOf_=None): 658 | self.ID = _cast(None, ID) 659 | self.name = _cast(None, name) 660 | self.valueOf_ = valueOf_ 661 | def factory(*args_, **kwargs_): 662 | if semTypeRefType.subclass: 663 | return semTypeRefType.subclass(*args_, **kwargs_) 664 | else: 665 | return semTypeRefType(*args_, **kwargs_) 666 | factory = staticmethod(factory) 667 | def get_ID(self): return self.ID 668 | def set_ID(self, ID): self.ID = ID 669 | def get_name(self): return self.name 670 | def set_name(self, name): self.name = name 671 | def get_valueOf_(self): return self.valueOf_ 672 | def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 673 | def export(self, outfile, level, namespace_='fn:', name_='semTypeRefType', namespacedef_=''): 674 | showIndent(outfile, level) 675 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 676 | self.exportAttributes(outfile, level, [], namespace_, name_='semTypeRefType') 677 | if self.hasContent_(): 678 | outfile.write('>') 679 | outfile.write(self.valueOf_) 680 | self.exportChildren(outfile, level + 1, namespace_, name_) 681 | outfile.write('\n' % (namespace_, name_)) 682 | else: 683 | outfile.write('/>\n') 684 | def exportAttributes(self, outfile, level, already_processed, namespace_='fn:', name_='semTypeRefType'): 685 | if self.ID is not None and 'ID' not in already_processed: 686 | already_processed.append('ID') 687 | outfile.write(' ID=%s' % (quote_attrib(self.ID), )) 688 | if self.name is not None and 'name' not in already_processed: 689 | already_processed.append('name') 690 | outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), )) 691 | def exportChildren(self, outfile, level, namespace_='fn:', name_='semTypeRefType', fromsubclass_=False): 692 | pass 693 | def hasContent_(self): 694 | if ( 695 | self.valueOf_ 696 | ): 697 | return True 698 | else: 699 | return False 700 | def exportLiteral(self, outfile, level, name_='semTypeRefType'): 701 | level += 1 702 | self.exportLiteralAttributes(outfile, level, [], name_) 703 | if self.hasContent_(): 704 | self.exportLiteralChildren(outfile, level, name_) 705 | showIndent(outfile, level) 706 | outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) 707 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 708 | if self.ID is not None and 'ID' not in already_processed: 709 | already_processed.append('ID') 710 | showIndent(outfile, level) 711 | outfile.write('ID = %s,\n' % (self.ID,)) 712 | if self.name is not None and 'name' not in already_processed: 713 | already_processed.append('name') 714 | showIndent(outfile, level) 715 | outfile.write('name = "%s",\n' % (self.name,)) 716 | def exportLiteralChildren(self, outfile, level, name_): 717 | pass 718 | def build(self, node): 719 | self.buildAttributes(node, node.attrib, []) 720 | self.valueOf_ = get_all_text_(node) 721 | for child in node: 722 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 723 | self.buildChildren(child, node, nodeName_) 724 | def buildAttributes(self, node, attrs, already_processed): 725 | value = attrs.get('ID') 726 | if value is not None and 'ID' not in already_processed: 727 | already_processed.append('ID') 728 | self.ID = value 729 | value = attrs.get('name') 730 | if value is not None and 'name' not in already_processed: 731 | already_processed.append('name') 732 | self.name = value 733 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 734 | pass 735 | # end class semTypeRefType 736 | 737 | 738 | USAGE_TEXT = """ 739 | Usage: python .py [ -s ] 740 | """ 741 | 742 | def usage(): 743 | print USAGE_TEXT 744 | sys.exit(1) 745 | 746 | 747 | def get_root_tag(node): 748 | tag = Tag_pattern_.match(node.tag).groups()[-1] 749 | rootClass = globals().get(tag) 750 | return tag, rootClass 751 | 752 | 753 | def parse(inFileName): 754 | doc = parsexml_(inFileName) 755 | rootNode = doc.getroot() 756 | rootTag, rootClass = get_root_tag(rootNode) 757 | if rootClass is None: 758 | rootTag = 'frameIndex' 759 | rootClass = frameIndex 760 | rootObj = rootClass.factory() 761 | rootObj.build(rootNode) 762 | # Enable Python to collect the space used by the DOM. 763 | doc = None 764 | sys.stdout.write('\n') 765 | rootObj.export(sys.stdout, 0, name_=rootTag, 766 | namespacedef_='') 767 | return rootObj 768 | 769 | 770 | def parseString(inString): 771 | from StringIO import StringIO 772 | doc = parsexml_(StringIO(inString)) 773 | rootNode = doc.getroot() 774 | rootTag, rootClass = get_root_tag(rootNode) 775 | if rootClass is None: 776 | rootTag = 'frameIndex' 777 | rootClass = frameIndex 778 | rootObj = rootClass.factory() 779 | rootObj.build(rootNode) 780 | # Enable Python to collect the space used by the DOM. 781 | doc = None 782 | sys.stdout.write('\n') 783 | rootObj.export(sys.stdout, 0, name_="frameIndex", 784 | namespacedef_='') 785 | return rootObj 786 | 787 | 788 | def parseLiteral(inFileName): 789 | doc = parsexml_(inFileName) 790 | rootNode = doc.getroot() 791 | rootTag, rootClass = get_root_tag(rootNode) 792 | if rootClass is None: 793 | rootTag = 'frameIndex' 794 | rootClass = frameIndex 795 | rootObj = rootClass.factory() 796 | rootObj.build(rootNode) 797 | # Enable Python to collect the space used by the DOM. 798 | doc = None 799 | sys.stdout.write('#from frameIndex import *\n\n') 800 | sys.stdout.write('import frameIndex as model_\n\n') 801 | sys.stdout.write('rootObj = model_.rootTag(\n') 802 | rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) 803 | sys.stdout.write(')\n') 804 | return rootObj 805 | 806 | 807 | def main(): 808 | args = sys.argv[1:] 809 | if len(args) == 1: 810 | parse(args[0]) 811 | else: 812 | usage() 813 | 814 | 815 | if __name__ == '__main__': 816 | #import pdb; pdb.set_trace() 817 | main() 818 | 819 | 820 | __all__ = [ 821 | "frame", 822 | "frameIndex", 823 | "lexemeType", 824 | "semTypeRefType" 825 | ] 826 | -------------------------------------------------------------------------------- /1.5/frameIndexSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:00:42 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class frameIndexSub(supermod.frameIndex): 74 | def __init__(self, frame=None): 75 | super(frameIndexSub, self).__init__(frame, ) 76 | supermod.frameIndex.subclass = frameIndexSub 77 | # end class frameIndexSub 78 | 79 | 80 | class frameSub(supermod.frame): 81 | def __init__(self, mDate=None, name=None, ID=None, valueOf_=None): 82 | super(frameSub, self).__init__(mDate, name, ID, valueOf_, ) 83 | supermod.frame.subclass = frameSub 84 | # end class frameSub 85 | 86 | 87 | class lexemeTypeSub(supermod.lexemeType): 88 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 89 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 90 | supermod.lexemeType.subclass = lexemeTypeSub 91 | # end class lexemeTypeSub 92 | 93 | 94 | class semTypeRefTypeSub(supermod.semTypeRefType): 95 | def __init__(self, ID=None, name=None, valueOf_=None): 96 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 97 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 98 | # end class semTypeRefTypeSub 99 | 100 | 101 | 102 | def get_root_tag(node): 103 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 104 | rootClass = None 105 | if hasattr(supermod, tag): 106 | rootClass = getattr(supermod, tag) 107 | return tag, rootClass 108 | 109 | 110 | def parse(inFilename): 111 | doc = parsexml_(inFilename) 112 | rootNode = doc.getroot() 113 | rootTag, rootClass = get_root_tag(rootNode) 114 | if rootClass is None: 115 | rootTag = 'frameIndex' 116 | rootClass = supermod.frameIndex 117 | rootObj = rootClass.factory() 118 | rootObj.build(rootNode) 119 | # Enable Python to collect the space used by the DOM. 120 | doc = None 121 | sys.stdout.write('\n') 122 | rootObj.export(sys.stdout, 0, name_=rootTag, 123 | namespacedef_='') 124 | doc = None 125 | return rootObj 126 | 127 | 128 | def parseString(inString): 129 | from StringIO import StringIO 130 | doc = parsexml_(StringIO(inString)) 131 | rootNode = doc.getroot() 132 | rootTag, rootClass = get_root_tag(rootNode) 133 | if rootClass is None: 134 | rootTag = 'frameIndex' 135 | rootClass = supermod.frameIndex 136 | rootObj = rootClass.factory() 137 | rootObj.build(rootNode) 138 | # Enable Python to collect the space used by the DOM. 139 | doc = None 140 | sys.stdout.write('\n') 141 | rootObj.export(sys.stdout, 0, name_=rootTag, 142 | namespacedef_='') 143 | return rootObj 144 | 145 | 146 | def parseLiteral(inFilename): 147 | doc = parsexml_(inFilename) 148 | rootNode = doc.getroot() 149 | rootTag, rootClass = get_root_tag(rootNode) 150 | if rootClass is None: 151 | rootTag = 'frameIndex' 152 | rootClass = supermod.frameIndex 153 | rootObj = rootClass.factory() 154 | rootObj.build(rootNode) 155 | # Enable Python to collect the space used by the DOM. 156 | doc = None 157 | sys.stdout.write('#from ??? import *\n\n') 158 | sys.stdout.write('import ??? as model_\n\n') 159 | sys.stdout.write('rootObj = model_.frameIndex(\n') 160 | rootObj.exportLiteral(sys.stdout, 0, name_="frameIndex") 161 | sys.stdout.write(')\n') 162 | return rootObj 163 | 164 | 165 | USAGE_TEXT = """ 166 | Usage: python ???.py 167 | """ 168 | 169 | def usage(): 170 | print USAGE_TEXT 171 | sys.exit(1) 172 | 173 | 174 | def main(): 175 | args = sys.argv[1:] 176 | if len(args) != 1: 177 | usage() 178 | infilename = args[0] 179 | root = parse(infilename) 180 | 181 | 182 | if __name__ == '__main__': 183 | #import pdb; pdb.set_trace() 184 | main() 185 | 186 | 187 | -------------------------------------------------------------------------------- /1.5/frameSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:00:26 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class frameSub(supermod.frame): 74 | def __init__(self, cDate=None, cBy=None, ID=None, name=None, definition=None, semType=None, FE=None, FEcoreSet=None, frameRelation=None, lexUnit=None): 75 | super(frameSub, self).__init__(cDate, cBy, ID, name, definition, semType, FE, FEcoreSet, frameRelation, lexUnit, ) 76 | supermod.frame.subclass = frameSub 77 | # end class frameSub 78 | 79 | 80 | class FEcoreSetSub(supermod.FEcoreSet): 81 | def __init__(self, memberFE=None): 82 | super(FEcoreSetSub, self).__init__(memberFE, ) 83 | supermod.FEcoreSet.subclass = FEcoreSetSub 84 | # end class FEcoreSetSub 85 | 86 | 87 | class FETypeSub(supermod.FEType): 88 | def __init__(self, name=None, abbrev=None, fgColor=None, bgColor=None, cDate=None, coreType=None, cBy=None, ID=None, definition=None, semType=None, requiresFE=None, excludesFE=None): 89 | super(FETypeSub, self).__init__(name, abbrev, fgColor, bgColor, cDate, coreType, cBy, ID, definition, semType, requiresFE, excludesFE, ) 90 | supermod.FEType.subclass = FETypeSub 91 | # end class FETypeSub 92 | 93 | 94 | class internalFrameRelationFETypeSub(supermod.internalFrameRelationFEType): 95 | def __init__(self, ID=None, name=None, valueOf_=None): 96 | super(internalFrameRelationFETypeSub, self).__init__(ID, name, valueOf_, ) 97 | supermod.internalFrameRelationFEType.subclass = internalFrameRelationFETypeSub 98 | # end class internalFrameRelationFETypeSub 99 | 100 | 101 | class relatedFramesTypeSub(supermod.relatedFramesType): 102 | def __init__(self, type_=None, relatedFrame=None): 103 | super(relatedFramesTypeSub, self).__init__(type_, relatedFrame, ) 104 | supermod.relatedFramesType.subclass = relatedFramesTypeSub 105 | # end class relatedFramesTypeSub 106 | 107 | 108 | class frameLUTypeSub(supermod.frameLUType): 109 | def __init__(self, status=None, name=None, POS=None, cDate=None, incorporatedFE=None, cBy=None, lemmaID=None, ID=None, definition=None, sentenceCount=None, lexeme=None, semType=None): 110 | super(frameLUTypeSub, self).__init__(status, name, POS, cDate, incorporatedFE, cBy, lemmaID, ID, definition, sentenceCount, lexeme, semType, ) 111 | supermod.frameLUType.subclass = frameLUTypeSub 112 | # end class frameLUTypeSub 113 | 114 | 115 | class sentenceCountSub(supermod.sentenceCount): 116 | def __init__(self, total=None, annotated=None, valueOf_=None): 117 | super(sentenceCountSub, self).__init__(total, annotated, valueOf_, ) 118 | supermod.sentenceCount.subclass = sentenceCountSub 119 | # end class sentenceCountSub 120 | 121 | 122 | class lexemeTypeSub(supermod.lexemeType): 123 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 124 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 125 | supermod.lexemeType.subclass = lexemeTypeSub 126 | # end class lexemeTypeSub 127 | 128 | 129 | class semTypeRefTypeSub(supermod.semTypeRefType): 130 | def __init__(self, ID=None, name=None, valueOf_=None): 131 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 132 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 133 | # end class semTypeRefTypeSub 134 | 135 | 136 | 137 | def get_root_tag(node): 138 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 139 | rootClass = None 140 | if hasattr(supermod, tag): 141 | rootClass = getattr(supermod, tag) 142 | return tag, rootClass 143 | 144 | 145 | def parse(inFilename): 146 | doc = parsexml_(inFilename) 147 | rootNode = doc.getroot() 148 | rootTag, rootClass = get_root_tag(rootNode) 149 | if rootClass is None: 150 | rootTag = 'frame' 151 | rootClass = supermod.frame 152 | rootObj = rootClass.factory() 153 | rootObj.build(rootNode) 154 | # Enable Python to collect the space used by the DOM. 155 | doc = None 156 | sys.stdout.write('\n') 157 | rootObj.export(sys.stdout, 0, name_=rootTag, 158 | namespacedef_='') 159 | doc = None 160 | return rootObj 161 | 162 | 163 | def parseString(inString): 164 | from StringIO import StringIO 165 | doc = parsexml_(StringIO(inString)) 166 | rootNode = doc.getroot() 167 | rootTag, rootClass = get_root_tag(rootNode) 168 | if rootClass is None: 169 | rootTag = 'frame' 170 | rootClass = supermod.frame 171 | rootObj = rootClass.factory() 172 | rootObj.build(rootNode) 173 | # Enable Python to collect the space used by the DOM. 174 | doc = None 175 | sys.stdout.write('\n') 176 | rootObj.export(sys.stdout, 0, name_=rootTag, 177 | namespacedef_='') 178 | return rootObj 179 | 180 | 181 | def parseLiteral(inFilename): 182 | doc = parsexml_(inFilename) 183 | rootNode = doc.getroot() 184 | rootTag, rootClass = get_root_tag(rootNode) 185 | if rootClass is None: 186 | rootTag = 'frame' 187 | rootClass = supermod.frame 188 | rootObj = rootClass.factory() 189 | rootObj.build(rootNode) 190 | # Enable Python to collect the space used by the DOM. 191 | doc = None 192 | sys.stdout.write('#from ??? import *\n\n') 193 | sys.stdout.write('import ??? as model_\n\n') 194 | sys.stdout.write('rootObj = model_.frame(\n') 195 | rootObj.exportLiteral(sys.stdout, 0, name_="frame") 196 | sys.stdout.write(')\n') 197 | return rootObj 198 | 199 | 200 | USAGE_TEXT = """ 201 | Usage: python ???.py 202 | """ 203 | 204 | def usage(): 205 | print USAGE_TEXT 206 | sys.exit(1) 207 | 208 | 209 | def main(): 210 | args = sys.argv[1:] 211 | if len(args) != 1: 212 | usage() 213 | infilename = args[0] 214 | root = parse(infilename) 215 | 216 | 217 | if __name__ == '__main__': 218 | #import pdb; pdb.set_trace() 219 | main() 220 | 221 | 222 | -------------------------------------------------------------------------------- /1.5/fulltextIndexSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:02:36 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class fulltextIndexSub(supermod.fulltextIndex): 74 | def __init__(self, corpus=None): 75 | super(fulltextIndexSub, self).__init__(corpus, ) 76 | supermod.fulltextIndex.subclass = fulltextIndexSub 77 | # end class fulltextIndexSub 78 | 79 | 80 | class headerTypeSub(supermod.headerType): 81 | def __init__(self, corpus=None, frame=None): 82 | super(headerTypeSub, self).__init__(corpus, frame, ) 83 | supermod.headerType.subclass = headerTypeSub 84 | # end class headerTypeSub 85 | 86 | 87 | class frameSub(supermod.frame): 88 | def __init__(self, FE=None): 89 | super(frameSub, self).__init__(FE, ) 90 | supermod.frame.subclass = frameSub 91 | # end class frameSub 92 | 93 | 94 | class FESub(supermod.FE): 95 | def __init__(self, bgColor=None, abbrev=None, type_=None, name=None, fgColor=None, valueOf_=None): 96 | super(FESub, self).__init__(bgColor, abbrev, type_, name, fgColor, valueOf_, ) 97 | supermod.FE.subclass = FESub 98 | # end class FESub 99 | 100 | 101 | class corpDocTypeSub(supermod.corpDocType): 102 | def __init__(self, ID=None, name=None, document=None): 103 | super(corpDocTypeSub, self).__init__(ID, name, document, ) 104 | supermod.corpDocType.subclass = corpDocTypeSub 105 | # end class corpDocTypeSub 106 | 107 | 108 | class documentSub(supermod.document): 109 | def __init__(self, ID=None, description=None, valueOf_=None): 110 | super(documentSub, self).__init__(ID, description, valueOf_, ) 111 | supermod.document.subclass = documentSub 112 | # end class documentSub 113 | 114 | 115 | class lexemeTypeSub(supermod.lexemeType): 116 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 117 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 118 | supermod.lexemeType.subclass = lexemeTypeSub 119 | # end class lexemeTypeSub 120 | 121 | 122 | class semTypeRefTypeSub(supermod.semTypeRefType): 123 | def __init__(self, ID=None, name=None, valueOf_=None): 124 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 125 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 126 | # end class semTypeRefTypeSub 127 | 128 | 129 | 130 | def get_root_tag(node): 131 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 132 | rootClass = None 133 | if hasattr(supermod, tag): 134 | rootClass = getattr(supermod, tag) 135 | return tag, rootClass 136 | 137 | 138 | def parse(inFilename): 139 | doc = parsexml_(inFilename) 140 | rootNode = doc.getroot() 141 | rootTag, rootClass = get_root_tag(rootNode) 142 | if rootClass is None: 143 | rootTag = 'fulltextIndex' 144 | rootClass = supermod.fulltextIndex 145 | rootObj = rootClass.factory() 146 | rootObj.build(rootNode) 147 | # Enable Python to collect the space used by the DOM. 148 | doc = None 149 | sys.stdout.write('\n') 150 | rootObj.export(sys.stdout, 0, name_=rootTag, 151 | namespacedef_='') 152 | doc = None 153 | return rootObj 154 | 155 | 156 | def parseString(inString): 157 | from StringIO import StringIO 158 | doc = parsexml_(StringIO(inString)) 159 | rootNode = doc.getroot() 160 | rootTag, rootClass = get_root_tag(rootNode) 161 | if rootClass is None: 162 | rootTag = 'fulltextIndex' 163 | rootClass = supermod.fulltextIndex 164 | rootObj = rootClass.factory() 165 | rootObj.build(rootNode) 166 | # Enable Python to collect the space used by the DOM. 167 | doc = None 168 | sys.stdout.write('\n') 169 | rootObj.export(sys.stdout, 0, name_=rootTag, 170 | namespacedef_='') 171 | return rootObj 172 | 173 | 174 | def parseLiteral(inFilename): 175 | doc = parsexml_(inFilename) 176 | rootNode = doc.getroot() 177 | rootTag, rootClass = get_root_tag(rootNode) 178 | if rootClass is None: 179 | rootTag = 'fulltextIndex' 180 | rootClass = supermod.fulltextIndex 181 | rootObj = rootClass.factory() 182 | rootObj.build(rootNode) 183 | # Enable Python to collect the space used by the DOM. 184 | doc = None 185 | sys.stdout.write('#from ??? import *\n\n') 186 | sys.stdout.write('import ??? as model_\n\n') 187 | sys.stdout.write('rootObj = model_.fulltextIndex(\n') 188 | rootObj.exportLiteral(sys.stdout, 0, name_="fulltextIndex") 189 | sys.stdout.write(')\n') 190 | return rootObj 191 | 192 | 193 | USAGE_TEXT = """ 194 | Usage: python ???.py 195 | """ 196 | 197 | def usage(): 198 | print USAGE_TEXT 199 | sys.exit(1) 200 | 201 | 202 | def main(): 203 | args = sys.argv[1:] 204 | if len(args) != 1: 205 | usage() 206 | infilename = args[0] 207 | root = parse(infilename) 208 | 209 | 210 | if __name__ == '__main__': 211 | #import pdb; pdb.set_trace() 212 | main() 213 | 214 | 215 | -------------------------------------------------------------------------------- /1.5/fulltextSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:03:33 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class fullTextAnnotationSub(supermod.fullTextAnnotation): 74 | def __init__(self, header=None, sentence=None): 75 | super(fullTextAnnotationSub, self).__init__(header, sentence, ) 76 | supermod.fullTextAnnotation.subclass = fullTextAnnotationSub 77 | # end class fullTextAnnotationSub 78 | 79 | 80 | class headerTypeSub(supermod.headerType): 81 | def __init__(self, corpus=None, frame=None): 82 | super(headerTypeSub, self).__init__(corpus, frame, ) 83 | supermod.headerType.subclass = headerTypeSub 84 | # end class headerTypeSub 85 | 86 | 87 | class frameSub(supermod.frame): 88 | def __init__(self, FE=None): 89 | super(frameSub, self).__init__(FE, ) 90 | supermod.frame.subclass = frameSub 91 | # end class frameSub 92 | 93 | 94 | class FESub(supermod.FE): 95 | def __init__(self, bgColor=None, abbrev=None, type_=None, name=None, fgColor=None, valueOf_=None): 96 | super(FESub, self).__init__(bgColor, abbrev, type_, name, fgColor, valueOf_, ) 97 | supermod.FE.subclass = FESub 98 | # end class FESub 99 | 100 | 101 | class corpDocTypeSub(supermod.corpDocType): 102 | def __init__(self, ID=None, name=None, document=None): 103 | super(corpDocTypeSub, self).__init__(ID, name, document, ) 104 | supermod.corpDocType.subclass = corpDocTypeSub 105 | # end class corpDocTypeSub 106 | 107 | 108 | class documentSub(supermod.document): 109 | def __init__(self, ID=None, description=None, valueOf_=None): 110 | super(documentSub, self).__init__(ID, description, valueOf_, ) 111 | supermod.document.subclass = documentSub 112 | # end class documentSub 113 | 114 | 115 | class lexemeTypeSub(supermod.lexemeType): 116 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 117 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 118 | supermod.lexemeType.subclass = lexemeTypeSub 119 | # end class lexemeTypeSub 120 | 121 | 122 | class semTypeRefTypeSub(supermod.semTypeRefType): 123 | def __init__(self, ID=None, name=None, valueOf_=None): 124 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 125 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 126 | # end class semTypeRefTypeSub 127 | 128 | 129 | class sentenceTypeSub(supermod.sentenceType): 130 | def __init__(self, docID=None, sentNo=None, paragNo=None, aPos=None, corpID=None, ID=None, text=None, annotationSet=None): 131 | super(sentenceTypeSub, self).__init__(docID, sentNo, paragNo, aPos, corpID, ID, text, annotationSet, ) 132 | supermod.sentenceType.subclass = sentenceTypeSub 133 | # end class sentenceTypeSub 134 | 135 | 136 | class annotationSetTypeSub(supermod.annotationSetType): 137 | def __init__(self, status=None, cxnID=None, luID=None, frameID=None, cDate=None, frameName=None, luName=None, cxnName=None, ID=None, layer=None): 138 | super(annotationSetTypeSub, self).__init__(status, cxnID, luID, frameID, cDate, frameName, luName, cxnName, ID, layer, ) 139 | supermod.annotationSetType.subclass = annotationSetTypeSub 140 | # end class annotationSetTypeSub 141 | 142 | 143 | class layerTypeSub(supermod.layerType): 144 | def __init__(self, name=None, rank=None, label=None): 145 | super(layerTypeSub, self).__init__(name, rank, label, ) 146 | supermod.layerType.subclass = layerTypeSub 147 | # end class layerTypeSub 148 | 149 | 150 | class labelTypeSub(supermod.labelType): 151 | def __init__(self, itype=None, name=None, bgColor=None, feID=None, start=None, end=None, cBy=None, fgColor=None, valueOf_=None): 152 | super(labelTypeSub, self).__init__(itype, name, bgColor, feID, start, end, cBy, fgColor, valueOf_, ) 153 | supermod.labelType.subclass = labelTypeSub 154 | # end class labelTypeSub 155 | 156 | 157 | 158 | def get_root_tag(node): 159 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 160 | rootClass = None 161 | if hasattr(supermod, tag): 162 | rootClass = getattr(supermod, tag) 163 | return tag, rootClass 164 | 165 | 166 | def parse(inFilename): 167 | doc = parsexml_(inFilename) 168 | rootNode = doc.getroot() 169 | rootTag, rootClass = get_root_tag(rootNode) 170 | if rootClass is None: 171 | rootTag = 'fullTextAnnotation' 172 | rootClass = supermod.fullTextAnnotation 173 | rootObj = rootClass.factory() 174 | rootObj.build(rootNode) 175 | # Enable Python to collect the space used by the DOM. 176 | doc = None 177 | sys.stdout.write('\n') 178 | rootObj.export(sys.stdout, 0, name_=rootTag, 179 | namespacedef_='') 180 | doc = None 181 | return rootObj 182 | 183 | 184 | def parseString(inString): 185 | from StringIO import StringIO 186 | doc = parsexml_(StringIO(inString)) 187 | rootNode = doc.getroot() 188 | rootTag, rootClass = get_root_tag(rootNode) 189 | if rootClass is None: 190 | rootTag = 'fullTextAnnotation' 191 | rootClass = supermod.fullTextAnnotation 192 | rootObj = rootClass.factory() 193 | rootObj.build(rootNode) 194 | # Enable Python to collect the space used by the DOM. 195 | doc = None 196 | sys.stdout.write('\n') 197 | rootObj.export(sys.stdout, 0, name_=rootTag, 198 | namespacedef_='') 199 | return rootObj 200 | 201 | 202 | def parseLiteral(inFilename): 203 | doc = parsexml_(inFilename) 204 | rootNode = doc.getroot() 205 | rootTag, rootClass = get_root_tag(rootNode) 206 | if rootClass is None: 207 | rootTag = 'fullTextAnnotation' 208 | rootClass = supermod.fullTextAnnotation 209 | rootObj = rootClass.factory() 210 | rootObj.build(rootNode) 211 | # Enable Python to collect the space used by the DOM. 212 | doc = None 213 | sys.stdout.write('#from ??? import *\n\n') 214 | sys.stdout.write('import ??? as model_\n\n') 215 | sys.stdout.write('rootObj = model_.fullTextAnnotation(\n') 216 | rootObj.exportLiteral(sys.stdout, 0, name_="fullTextAnnotation") 217 | sys.stdout.write(')\n') 218 | return rootObj 219 | 220 | 221 | USAGE_TEXT = """ 222 | Usage: python ???.py 223 | """ 224 | 225 | def usage(): 226 | print USAGE_TEXT 227 | sys.exit(1) 228 | 229 | 230 | def main(): 231 | args = sys.argv[1:] 232 | if len(args) != 1: 233 | usage() 234 | infilename = args[0] 235 | root = parse(infilename) 236 | 237 | 238 | if __name__ == '__main__': 239 | #import pdb; pdb.set_trace() 240 | main() 241 | 242 | 243 | -------------------------------------------------------------------------------- /1.5/headerSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:01:00 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class headerTypeSub(supermod.headerType): 74 | def __init__(self, corpus=None, frame=None): 75 | super(headerTypeSub, self).__init__(corpus, frame, ) 76 | supermod.headerType.subclass = headerTypeSub 77 | # end class headerTypeSub 78 | 79 | 80 | class frameSub(supermod.frame): 81 | def __init__(self, FE=None): 82 | super(frameSub, self).__init__(FE, ) 83 | supermod.frame.subclass = frameSub 84 | # end class frameSub 85 | 86 | 87 | class FESub(supermod.FE): 88 | def __init__(self, bgColor=None, abbrev=None, type_=None, name=None, fgColor=None, valueOf_=None): 89 | super(FESub, self).__init__(bgColor, abbrev, type_, name, fgColor, valueOf_, ) 90 | supermod.FE.subclass = FESub 91 | # end class FESub 92 | 93 | 94 | class corpDocTypeSub(supermod.corpDocType): 95 | def __init__(self, ID=None, name=None, document=None): 96 | super(corpDocTypeSub, self).__init__(ID, name, document, ) 97 | supermod.corpDocType.subclass = corpDocTypeSub 98 | # end class corpDocTypeSub 99 | 100 | 101 | class documentSub(supermod.document): 102 | def __init__(self, ID=None, description=None, valueOf_=None): 103 | super(documentSub, self).__init__(ID, description, valueOf_, ) 104 | supermod.document.subclass = documentSub 105 | # end class documentSub 106 | 107 | 108 | class lexemeTypeSub(supermod.lexemeType): 109 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 110 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 111 | supermod.lexemeType.subclass = lexemeTypeSub 112 | # end class lexemeTypeSub 113 | 114 | 115 | class semTypeRefTypeSub(supermod.semTypeRefType): 116 | def __init__(self, ID=None, name=None, valueOf_=None): 117 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 118 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 119 | # end class semTypeRefTypeSub 120 | 121 | 122 | 123 | def get_root_tag(node): 124 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 125 | rootClass = None 126 | if hasattr(supermod, tag): 127 | rootClass = getattr(supermod, tag) 128 | return tag, rootClass 129 | 130 | 131 | def parse(inFilename): 132 | doc = parsexml_(inFilename) 133 | rootNode = doc.getroot() 134 | rootTag, rootClass = get_root_tag(rootNode) 135 | if rootClass is None: 136 | rootTag = 'headerType' 137 | rootClass = supermod.headerType 138 | rootObj = rootClass.factory() 139 | rootObj.build(rootNode) 140 | # Enable Python to collect the space used by the DOM. 141 | doc = None 142 | sys.stdout.write('\n') 143 | rootObj.export(sys.stdout, 0, name_=rootTag, 144 | namespacedef_='') 145 | doc = None 146 | return rootObj 147 | 148 | 149 | def parseString(inString): 150 | from StringIO import StringIO 151 | doc = parsexml_(StringIO(inString)) 152 | rootNode = doc.getroot() 153 | rootTag, rootClass = get_root_tag(rootNode) 154 | if rootClass is None: 155 | rootTag = 'headerType' 156 | rootClass = supermod.headerType 157 | rootObj = rootClass.factory() 158 | rootObj.build(rootNode) 159 | # Enable Python to collect the space used by the DOM. 160 | doc = None 161 | sys.stdout.write('\n') 162 | rootObj.export(sys.stdout, 0, name_=rootTag, 163 | namespacedef_='') 164 | return rootObj 165 | 166 | 167 | def parseLiteral(inFilename): 168 | doc = parsexml_(inFilename) 169 | rootNode = doc.getroot() 170 | rootTag, rootClass = get_root_tag(rootNode) 171 | if rootClass is None: 172 | rootTag = 'headerType' 173 | rootClass = supermod.headerType 174 | rootObj = rootClass.factory() 175 | rootObj.build(rootNode) 176 | # Enable Python to collect the space used by the DOM. 177 | doc = None 178 | sys.stdout.write('#from ??? import *\n\n') 179 | sys.stdout.write('import ??? as model_\n\n') 180 | sys.stdout.write('rootObj = model_.headerType(\n') 181 | rootObj.exportLiteral(sys.stdout, 0, name_="headerType") 182 | sys.stdout.write(')\n') 183 | return rootObj 184 | 185 | 186 | USAGE_TEXT = """ 187 | Usage: python ???.py 188 | """ 189 | 190 | def usage(): 191 | print USAGE_TEXT 192 | sys.exit(1) 193 | 194 | 195 | def main(): 196 | args = sys.argv[1:] 197 | if len(args) != 1: 198 | usage() 199 | infilename = args[0] 200 | root = parse(infilename) 201 | 202 | 203 | if __name__ == '__main__': 204 | #import pdb; pdb.set_trace() 205 | main() 206 | 207 | 208 | -------------------------------------------------------------------------------- /1.5/lexUnitSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:02:02 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class lexUnitSub(supermod.lexUnit): 74 | def __init__(self, status=None, name=None, frame=None, POS=None, frameID=None, incorporatedFE=None, totalAnnotated=None, ID=None, header=None, definition=None, lexeme=None, semType=None, valences=None, subCorpus=None): 75 | super(lexUnitSub, self).__init__(status, name, frame, POS, frameID, incorporatedFE, totalAnnotated, ID, header, definition, lexeme, semType, valences, subCorpus, ) 76 | supermod.lexUnit.subclass = lexUnitSub 77 | # end class lexUnitSub 78 | 79 | 80 | class valencesTypeSub(supermod.valencesType): 81 | def __init__(self, governor=None, FERealization=None, FEGroupRealization=None): 82 | super(valencesTypeSub, self).__init__(governor, FERealization, FEGroupRealization, ) 83 | supermod.valencesType.subclass = valencesTypeSub 84 | # end class valencesTypeSub 85 | 86 | 87 | class subCorpusTypeSub(supermod.subCorpusType): 88 | def __init__(self, name=None, sentence=None): 89 | super(subCorpusTypeSub, self).__init__(name, sentence, ) 90 | supermod.subCorpusType.subclass = subCorpusTypeSub 91 | # end class subCorpusTypeSub 92 | 93 | 94 | class governorTypeSub(supermod.governorType): 95 | def __init__(self, lemma=None, type_=None, annoSet=None): 96 | super(governorTypeSub, self).__init__(lemma, type_, annoSet, ) 97 | supermod.governorType.subclass = governorTypeSub 98 | # end class governorTypeSub 99 | 100 | 101 | class FERealizationTypeSub(supermod.FERealizationType): 102 | def __init__(self, total=None, FE=None, pattern=None): 103 | super(FERealizationTypeSub, self).__init__(total, FE, pattern, ) 104 | supermod.FERealizationType.subclass = FERealizationTypeSub 105 | # end class FERealizationTypeSub 106 | 107 | 108 | class patternSub(supermod.pattern): 109 | def __init__(self, total=None, valenceUnit=None, annoSet=None): 110 | super(patternSub, self).__init__(total, valenceUnit, annoSet, ) 111 | supermod.pattern.subclass = patternSub 112 | # end class patternSub 113 | 114 | 115 | class FEGroupRealizationTypeSub(supermod.FEGroupRealizationType): 116 | def __init__(self, total=None, FE=None, pattern=None): 117 | super(FEGroupRealizationTypeSub, self).__init__(total, FE, pattern, ) 118 | supermod.FEGroupRealizationType.subclass = FEGroupRealizationTypeSub 119 | # end class FEGroupRealizationTypeSub 120 | 121 | 122 | class annoSetTypeSub(supermod.annoSetType): 123 | def __init__(self, ID=None, valueOf_=None): 124 | super(annoSetTypeSub, self).__init__(ID, valueOf_, ) 125 | supermod.annoSetType.subclass = annoSetTypeSub 126 | # end class annoSetTypeSub 127 | 128 | 129 | class FEValenceTypeSub(supermod.FEValenceType): 130 | def __init__(self, name=None, valueOf_=None): 131 | super(FEValenceTypeSub, self).__init__(name, valueOf_, ) 132 | supermod.FEValenceType.subclass = FEValenceTypeSub 133 | # end class FEValenceTypeSub 134 | 135 | 136 | class valenceUnitTypeSub(supermod.valenceUnitType): 137 | def __init__(self, GF=None, FE=None, PT=None, valueOf_=None): 138 | super(valenceUnitTypeSub, self).__init__(GF, FE, PT, valueOf_, ) 139 | supermod.valenceUnitType.subclass = valenceUnitTypeSub 140 | # end class valenceUnitTypeSub 141 | 142 | 143 | class lexemeTypeSub(supermod.lexemeType): 144 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 145 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 146 | supermod.lexemeType.subclass = lexemeTypeSub 147 | # end class lexemeTypeSub 148 | 149 | 150 | class semTypeRefTypeSub(supermod.semTypeRefType): 151 | def __init__(self, ID=None, name=None, valueOf_=None): 152 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 153 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 154 | # end class semTypeRefTypeSub 155 | 156 | 157 | class headerTypeSub(supermod.headerType): 158 | def __init__(self, corpus=None, frame=None): 159 | super(headerTypeSub, self).__init__(corpus, frame, ) 160 | supermod.headerType.subclass = headerTypeSub 161 | # end class headerTypeSub 162 | 163 | 164 | class frameSub(supermod.frame): 165 | def __init__(self, FE=None): 166 | super(frameSub, self).__init__(FE, ) 167 | supermod.frame.subclass = frameSub 168 | # end class frameSub 169 | 170 | 171 | class FESub(supermod.FE): 172 | def __init__(self, bgColor=None, abbrev=None, type_=None, name=None, fgColor=None, valueOf_=None): 173 | super(FESub, self).__init__(bgColor, abbrev, type_, name, fgColor, valueOf_, ) 174 | supermod.FE.subclass = FESub 175 | # end class FESub 176 | 177 | 178 | class corpDocTypeSub(supermod.corpDocType): 179 | def __init__(self, ID=None, name=None, document=None): 180 | super(corpDocTypeSub, self).__init__(ID, name, document, ) 181 | supermod.corpDocType.subclass = corpDocTypeSub 182 | # end class corpDocTypeSub 183 | 184 | 185 | class documentSub(supermod.document): 186 | def __init__(self, ID=None, description=None, valueOf_=None): 187 | super(documentSub, self).__init__(ID, description, valueOf_, ) 188 | supermod.document.subclass = documentSub 189 | # end class documentSub 190 | 191 | 192 | class sentenceTypeSub(supermod.sentenceType): 193 | def __init__(self, docID=None, sentNo=None, paragNo=None, aPos=None, corpID=None, ID=None, text=None, annotationSet=None): 194 | super(sentenceTypeSub, self).__init__(docID, sentNo, paragNo, aPos, corpID, ID, text, annotationSet, ) 195 | supermod.sentenceType.subclass = sentenceTypeSub 196 | # end class sentenceTypeSub 197 | 198 | 199 | class annotationSetTypeSub(supermod.annotationSetType): 200 | def __init__(self, status=None, cxnID=None, luID=None, frameID=None, cDate=None, frameName=None, luName=None, cxnName=None, ID=None, layer=None): 201 | super(annotationSetTypeSub, self).__init__(status, cxnID, luID, frameID, cDate, frameName, luName, cxnName, ID, layer, ) 202 | supermod.annotationSetType.subclass = annotationSetTypeSub 203 | # end class annotationSetTypeSub 204 | 205 | 206 | class layerTypeSub(supermod.layerType): 207 | def __init__(self, name=None, rank=None, label=None): 208 | super(layerTypeSub, self).__init__(name, rank, label, ) 209 | supermod.layerType.subclass = layerTypeSub 210 | # end class layerTypeSub 211 | 212 | 213 | class labelTypeSub(supermod.labelType): 214 | def __init__(self, itype=None, name=None, bgColor=None, feID=None, start=None, end=None, cBy=None, fgColor=None, valueOf_=None): 215 | super(labelTypeSub, self).__init__(itype, name, bgColor, feID, start, end, cBy, fgColor, valueOf_, ) 216 | supermod.labelType.subclass = labelTypeSub 217 | # end class labelTypeSub 218 | 219 | 220 | 221 | def get_root_tag(node): 222 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 223 | rootClass = None 224 | if hasattr(supermod, tag): 225 | rootClass = getattr(supermod, tag) 226 | return tag, rootClass 227 | 228 | 229 | def parse(inFilename): 230 | doc = parsexml_(inFilename) 231 | rootNode = doc.getroot() 232 | rootTag, rootClass = get_root_tag(rootNode) 233 | if rootClass is None: 234 | rootTag = 'lexUnit' 235 | rootClass = supermod.lexUnit 236 | rootObj = rootClass.factory() 237 | rootObj.build(rootNode) 238 | # Enable Python to collect the space used by the DOM. 239 | doc = None 240 | sys.stdout.write('\n') 241 | rootObj.export(sys.stdout, 0, name_=rootTag, 242 | namespacedef_='') 243 | doc = None 244 | return rootObj 245 | 246 | 247 | def parseString(inString): 248 | from StringIO import StringIO 249 | doc = parsexml_(StringIO(inString)) 250 | rootNode = doc.getroot() 251 | rootTag, rootClass = get_root_tag(rootNode) 252 | if rootClass is None: 253 | rootTag = 'lexUnit' 254 | rootClass = supermod.lexUnit 255 | rootObj = rootClass.factory() 256 | rootObj.build(rootNode) 257 | # Enable Python to collect the space used by the DOM. 258 | doc = None 259 | sys.stdout.write('\n') 260 | rootObj.export(sys.stdout, 0, name_=rootTag, 261 | namespacedef_='') 262 | return rootObj 263 | 264 | 265 | def parseLiteral(inFilename): 266 | doc = parsexml_(inFilename) 267 | rootNode = doc.getroot() 268 | rootTag, rootClass = get_root_tag(rootNode) 269 | if rootClass is None: 270 | rootTag = 'lexUnit' 271 | rootClass = supermod.lexUnit 272 | rootObj = rootClass.factory() 273 | rootObj.build(rootNode) 274 | # Enable Python to collect the space used by the DOM. 275 | doc = None 276 | sys.stdout.write('#from ??? import *\n\n') 277 | sys.stdout.write('import ??? as model_\n\n') 278 | sys.stdout.write('rootObj = model_.lexUnit(\n') 279 | rootObj.exportLiteral(sys.stdout, 0, name_="lexUnit") 280 | sys.stdout.write(')\n') 281 | return rootObj 282 | 283 | 284 | USAGE_TEXT = """ 285 | Usage: python ???.py 286 | """ 287 | 288 | def usage(): 289 | print USAGE_TEXT 290 | sys.exit(1) 291 | 292 | 293 | def main(): 294 | args = sys.argv[1:] 295 | if len(args) != 1: 296 | usage() 297 | infilename = args[0] 298 | root = parse(infilename) 299 | 300 | 301 | if __name__ == '__main__': 302 | #import pdb; pdb.set_trace() 303 | main() 304 | 305 | 306 | -------------------------------------------------------------------------------- /1.5/luIndex.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # Generated Fri Apr 15 16:01:18 2011 by generateDS.py version 2.4c. 6 | # 7 | 8 | import sys 9 | import getopt 10 | import re as re_ 11 | 12 | etree_ = None 13 | Verbose_import_ = False 14 | ( XMLParser_import_none, XMLParser_import_lxml, 15 | XMLParser_import_elementtree 16 | ) = range(3) 17 | XMLParser_import_library = None 18 | try: 19 | # lxml 20 | from lxml import etree as etree_ 21 | XMLParser_import_library = XMLParser_import_lxml 22 | if Verbose_import_: 23 | print("running with lxml.etree") 24 | except ImportError: 25 | try: 26 | # cElementTree from Python 2.5+ 27 | import xml.etree.cElementTree as etree_ 28 | XMLParser_import_library = XMLParser_import_elementtree 29 | if Verbose_import_: 30 | print("running with cElementTree on Python 2.5+") 31 | except ImportError: 32 | try: 33 | # ElementTree from Python 2.5+ 34 | import xml.etree.ElementTree as etree_ 35 | XMLParser_import_library = XMLParser_import_elementtree 36 | if Verbose_import_: 37 | print("running with ElementTree on Python 2.5+") 38 | except ImportError: 39 | try: 40 | # normal cElementTree install 41 | import cElementTree as etree_ 42 | XMLParser_import_library = XMLParser_import_elementtree 43 | if Verbose_import_: 44 | print("running with cElementTree") 45 | except ImportError: 46 | try: 47 | # normal ElementTree install 48 | import elementtree.ElementTree as etree_ 49 | XMLParser_import_library = XMLParser_import_elementtree 50 | if Verbose_import_: 51 | print("running with ElementTree") 52 | except ImportError: 53 | raise ImportError("Failed to import ElementTree from any known place") 54 | 55 | def parsexml_(*args, **kwargs): 56 | if (XMLParser_import_library == XMLParser_import_lxml and 57 | 'parser' not in kwargs): 58 | # Use the lxml ElementTree compatible parser so that, e.g., 59 | # we ignore comments. 60 | kwargs['parser'] = etree_.ETCompatXMLParser() 61 | doc = etree_.parse(*args, **kwargs) 62 | return doc 63 | 64 | # 65 | # User methods 66 | # 67 | # Calls to the methods in these classes are generated by generateDS.py. 68 | # You can replace these methods by re-implementing the following class 69 | # in a module named generatedssuper.py. 70 | 71 | try: 72 | from generatedssuper import GeneratedsSuper 73 | except ImportError, exp: 74 | 75 | class GeneratedsSuper(object): 76 | def gds_format_string(self, input_data, input_name=''): 77 | return input_data 78 | def gds_validate_string(self, input_data, node, input_name=''): 79 | return input_data 80 | def gds_format_integer(self, input_data, input_name=''): 81 | return '%d' % input_data 82 | def gds_validate_integer(self, input_data, node, input_name=''): 83 | return input_data 84 | def gds_format_integer_list(self, input_data, input_name=''): 85 | return '%s' % input_data 86 | def gds_validate_integer_list(self, input_data, node, input_name=''): 87 | values = input_data.split() 88 | for value in values: 89 | try: 90 | fvalue = float(value) 91 | except (TypeError, ValueError), exp: 92 | raise_parse_error(node, 'Requires sequence of integers') 93 | return input_data 94 | def gds_format_float(self, input_data, input_name=''): 95 | return '%f' % input_data 96 | def gds_validate_float(self, input_data, node, input_name=''): 97 | return input_data 98 | def gds_format_float_list(self, input_data, input_name=''): 99 | return '%s' % input_data 100 | def gds_validate_float_list(self, input_data, node, input_name=''): 101 | values = input_data.split() 102 | for value in values: 103 | try: 104 | fvalue = float(value) 105 | except (TypeError, ValueError), exp: 106 | raise_parse_error(node, 'Requires sequence of floats') 107 | return input_data 108 | def gds_format_double(self, input_data, input_name=''): 109 | return '%e' % input_data 110 | def gds_validate_double(self, input_data, node, input_name=''): 111 | return input_data 112 | def gds_format_double_list(self, input_data, input_name=''): 113 | return '%s' % input_data 114 | def gds_validate_double_list(self, input_data, node, input_name=''): 115 | values = input_data.split() 116 | for value in values: 117 | try: 118 | fvalue = float(value) 119 | except (TypeError, ValueError), exp: 120 | raise_parse_error(node, 'Requires sequence of doubles') 121 | return input_data 122 | def gds_format_boolean(self, input_data, input_name=''): 123 | return '%s' % input_data 124 | def gds_validate_boolean(self, input_data, node, input_name=''): 125 | return input_data 126 | def gds_format_boolean_list(self, input_data, input_name=''): 127 | return '%s' % input_data 128 | def gds_validate_boolean_list(self, input_data, node, input_name=''): 129 | values = input_data.split() 130 | for value in values: 131 | if value not in ('true', '1', 'false', '0', ): 132 | raise_parse_error(node, 'Requires sequence of booleans ("true", "1", "false", "0")') 133 | return input_data 134 | def gds_str_lower(self, instring): 135 | return instring.lower() 136 | def get_path_(self, node): 137 | path_list = [] 138 | self.get_path_list_(node, path_list) 139 | path_list.reverse() 140 | path = '/'.join(path_list) 141 | return path 142 | Tag_strip_pattern_ = re_.compile(r'\{.*\}') 143 | def get_path_list_(self, node, path_list): 144 | if node is None: 145 | return 146 | tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag) 147 | if tag: 148 | path_list.append(tag) 149 | self.get_path_list_(node.getparent(), path_list) 150 | 151 | 152 | # 153 | # If you have installed IPython you can uncomment and use the following. 154 | # IPython is available from http://ipython.scipy.org/. 155 | # 156 | 157 | ## from IPython.Shell import IPShellEmbed 158 | ## args = '' 159 | ## ipshell = IPShellEmbed(args, 160 | ## banner = 'Dropping into IPython', 161 | ## exit_msg = 'Leaving Interpreter, back to program.') 162 | 163 | # Then use the following line where and when you want to drop into the 164 | # IPython shell: 165 | # ipshell(' -- Entering ipshell.\nHit Ctrl-D to exit') 166 | 167 | # 168 | # Globals 169 | # 170 | 171 | ExternalEncoding = 'ascii' 172 | Tag_pattern_ = re_.compile(r'({.*})?(.*)') 173 | STRING_CLEANUP_PAT = re_.compile(r"[\n\r\s]+") 174 | 175 | # 176 | # Support/utility functions. 177 | # 178 | 179 | def showIndent(outfile, level): 180 | for idx in range(level): 181 | outfile.write(' ') 182 | 183 | def quote_xml(inStr): 184 | if not inStr: 185 | return '' 186 | s1 = (isinstance(inStr, basestring) and inStr or 187 | '%s' % inStr) 188 | s1 = s1.replace('&', '&') 189 | s1 = s1.replace('<', '<') 190 | s1 = s1.replace('>', '>') 191 | return s1 192 | 193 | def quote_attrib(inStr): 194 | s1 = (isinstance(inStr, basestring) and inStr or 195 | '%s' % inStr) 196 | s1 = s1.replace('&', '&') 197 | s1 = s1.replace('<', '<') 198 | s1 = s1.replace('>', '>') 199 | if '"' in s1: 200 | if "'" in s1: 201 | s1 = '"%s"' % s1.replace('"', """) 202 | else: 203 | s1 = "'%s'" % s1 204 | else: 205 | s1 = '"%s"' % s1 206 | return s1 207 | 208 | def quote_python(inStr): 209 | s1 = inStr 210 | if s1.find("'") == -1: 211 | if s1.find('\n') == -1: 212 | return "'%s'" % s1 213 | else: 214 | return "'''%s'''" % s1 215 | else: 216 | if s1.find('"') != -1: 217 | s1 = s1.replace('"', '\\"') 218 | if s1.find('\n') == -1: 219 | return '"%s"' % s1 220 | else: 221 | return '"""%s"""' % s1 222 | 223 | 224 | def get_all_text_(node): 225 | if node.text is not None: 226 | text = node.text 227 | else: 228 | text = '' 229 | for child in node: 230 | if child.tail is not None: 231 | text += child.tail 232 | return text 233 | 234 | 235 | class GDSParseError(Exception): 236 | pass 237 | 238 | def raise_parse_error(node, msg): 239 | if XMLParser_import_library == XMLParser_import_lxml: 240 | msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, ) 241 | else: 242 | msg = '%s (element %s)' % (msg, node.tag, ) 243 | raise GDSParseError(msg) 244 | 245 | 246 | class MixedContainer: 247 | # Constants for category: 248 | CategoryNone = 0 249 | CategoryText = 1 250 | CategorySimple = 2 251 | CategoryComplex = 3 252 | # Constants for content_type: 253 | TypeNone = 0 254 | TypeText = 1 255 | TypeString = 2 256 | TypeInteger = 3 257 | TypeFloat = 4 258 | TypeDecimal = 5 259 | TypeDouble = 6 260 | TypeBoolean = 7 261 | def __init__(self, category, content_type, name, value): 262 | self.category = category 263 | self.content_type = content_type 264 | self.name = name 265 | self.value = value 266 | def getCategory(self): 267 | return self.category 268 | def getContenttype(self, content_type): 269 | return self.content_type 270 | def getValue(self): 271 | return self.value 272 | def getName(self): 273 | return self.name 274 | def export(self, outfile, level, name, namespace): 275 | if self.category == MixedContainer.CategoryText: 276 | # Prevent exporting empty content as empty lines. 277 | if self.value.strip(): 278 | outfile.write(self.value) 279 | elif self.category == MixedContainer.CategorySimple: 280 | self.exportSimple(outfile, level, name) 281 | else: # category == MixedContainer.CategoryComplex 282 | self.value.export(outfile, level, namespace,name) 283 | def exportSimple(self, outfile, level, name): 284 | if self.content_type == MixedContainer.TypeString: 285 | outfile.write('<%s>%s' % (self.name, self.value, self.name)) 286 | elif self.content_type == MixedContainer.TypeInteger or \ 287 | self.content_type == MixedContainer.TypeBoolean: 288 | outfile.write('<%s>%d' % (self.name, self.value, self.name)) 289 | elif self.content_type == MixedContainer.TypeFloat or \ 290 | self.content_type == MixedContainer.TypeDecimal: 291 | outfile.write('<%s>%f' % (self.name, self.value, self.name)) 292 | elif self.content_type == MixedContainer.TypeDouble: 293 | outfile.write('<%s>%g' % (self.name, self.value, self.name)) 294 | def exportLiteral(self, outfile, level, name): 295 | if self.category == MixedContainer.CategoryText: 296 | showIndent(outfile, level) 297 | outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ 298 | (self.category, self.content_type, self.name, self.value)) 299 | elif self.category == MixedContainer.CategorySimple: 300 | showIndent(outfile, level) 301 | outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ 302 | (self.category, self.content_type, self.name, self.value)) 303 | else: # category == MixedContainer.CategoryComplex 304 | showIndent(outfile, level) 305 | outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \ 306 | (self.category, self.content_type, self.name,)) 307 | self.value.exportLiteral(outfile, level + 1) 308 | showIndent(outfile, level) 309 | outfile.write(')\n') 310 | 311 | 312 | class MemberSpec_(object): 313 | def __init__(self, name='', data_type='', container=0): 314 | self.name = name 315 | self.data_type = data_type 316 | self.container = container 317 | def set_name(self, name): self.name = name 318 | def get_name(self): return self.name 319 | def set_data_type(self, data_type): self.data_type = data_type 320 | def get_data_type_chain(self): return self.data_type 321 | def get_data_type(self): 322 | if isinstance(self.data_type, list): 323 | if len(self.data_type) > 0: 324 | return self.data_type[-1] 325 | else: 326 | return 'xs:string' 327 | else: 328 | return self.data_type 329 | def set_container(self, container): self.container = container 330 | def get_container(self): return self.container 331 | 332 | def _cast(typ, value): 333 | if typ is None or value is None: 334 | return value 335 | return typ(value) 336 | 337 | # 338 | # Data representation classes. 339 | # 340 | 341 | class luIndex(GeneratedsSuper): 342 | subclass = None 343 | superclass = None 344 | def __init__(self, legend=None, lu=None): 345 | self.legend = legend 346 | if lu is None: 347 | self.lu = [] 348 | else: 349 | self.lu = lu 350 | def factory(*args_, **kwargs_): 351 | if luIndex.subclass: 352 | return luIndex.subclass(*args_, **kwargs_) 353 | else: 354 | return luIndex(*args_, **kwargs_) 355 | factory = staticmethod(factory) 356 | def get_legend(self): return self.legend 357 | def set_legend(self, legend): self.legend = legend 358 | def get_lu(self): return self.lu 359 | def set_lu(self, lu): self.lu = lu 360 | def add_lu(self, value): self.lu.append(value) 361 | def insert_lu(self, index, value): self.lu[index] = value 362 | def export(self, outfile, level, namespace_='tns:', name_='luIndex', namespacedef_=''): 363 | showIndent(outfile, level) 364 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 365 | self.exportAttributes(outfile, level, [], namespace_, name_='luIndex') 366 | if self.hasContent_(): 367 | outfile.write('>\n') 368 | self.exportChildren(outfile, level + 1, namespace_, name_) 369 | showIndent(outfile, level) 370 | outfile.write('\n' % (namespace_, name_)) 371 | else: 372 | outfile.write('/>\n') 373 | def exportAttributes(self, outfile, level, already_processed, namespace_='tns:', name_='luIndex'): 374 | pass 375 | def exportChildren(self, outfile, level, namespace_='tns:', name_='luIndex', fromsubclass_=False): 376 | if self.legend: 377 | self.legend.export(outfile, level, namespace_, name_='legend', ) 378 | for lu_ in self.lu: 379 | lu_.export(outfile, level, namespace_, name_='lu') 380 | def hasContent_(self): 381 | if ( 382 | self.legend is not None or 383 | self.lu 384 | ): 385 | return True 386 | else: 387 | return False 388 | def exportLiteral(self, outfile, level, name_='luIndex'): 389 | level += 1 390 | self.exportLiteralAttributes(outfile, level, [], name_) 391 | if self.hasContent_(): 392 | self.exportLiteralChildren(outfile, level, name_) 393 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 394 | pass 395 | def exportLiteralChildren(self, outfile, level, name_): 396 | if self.legend is not None: 397 | showIndent(outfile, level) 398 | outfile.write('legend=model_.legend(\n') 399 | self.legend.exportLiteral(outfile, level) 400 | showIndent(outfile, level) 401 | outfile.write('),\n') 402 | showIndent(outfile, level) 403 | outfile.write('lu=[\n') 404 | level += 1 405 | for lu_ in self.lu: 406 | showIndent(outfile, level) 407 | outfile.write('model_.lu(\n') 408 | lu_.exportLiteral(outfile, level) 409 | showIndent(outfile, level) 410 | outfile.write('),\n') 411 | level -= 1 412 | showIndent(outfile, level) 413 | outfile.write('],\n') 414 | def build(self, node): 415 | self.buildAttributes(node, node.attrib, []) 416 | for child in node: 417 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 418 | self.buildChildren(child, node, nodeName_) 419 | def buildAttributes(self, node, attrs, already_processed): 420 | pass 421 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 422 | if nodeName_ == 'legend': 423 | obj_ = legend.factory() 424 | obj_.build(child_) 425 | self.set_legend(obj_) 426 | elif nodeName_ == 'lu': 427 | obj_ = lu.factory() 428 | obj_.build(child_) 429 | self.lu.append(obj_) 430 | # end class luIndex 431 | 432 | 433 | class legend(GeneratedsSuper): 434 | subclass = None 435 | superclass = None 436 | def __init__(self, statusType=None): 437 | if statusType is None: 438 | self.statusType = [] 439 | else: 440 | self.statusType = statusType 441 | def factory(*args_, **kwargs_): 442 | if legend.subclass: 443 | return legend.subclass(*args_, **kwargs_) 444 | else: 445 | return legend(*args_, **kwargs_) 446 | factory = staticmethod(factory) 447 | def get_statusType(self): return self.statusType 448 | def set_statusType(self, statusType): self.statusType = statusType 449 | def add_statusType(self, value): self.statusType.append(value) 450 | def insert_statusType(self, index, value): self.statusType[index] = value 451 | def export(self, outfile, level, namespace_='tns:', name_='legend', namespacedef_=''): 452 | showIndent(outfile, level) 453 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 454 | self.exportAttributes(outfile, level, [], namespace_, name_='legend') 455 | if self.hasContent_(): 456 | outfile.write('>\n') 457 | self.exportChildren(outfile, level + 1, namespace_, name_) 458 | showIndent(outfile, level) 459 | outfile.write('\n' % (namespace_, name_)) 460 | else: 461 | outfile.write('/>\n') 462 | def exportAttributes(self, outfile, level, already_processed, namespace_='tns:', name_='legend'): 463 | pass 464 | def exportChildren(self, outfile, level, namespace_='tns:', name_='legend', fromsubclass_=False): 465 | for statusType_ in self.statusType: 466 | statusType_.export(outfile, level, namespace_, name_='statusType') 467 | def hasContent_(self): 468 | if ( 469 | self.statusType 470 | ): 471 | return True 472 | else: 473 | return False 474 | def exportLiteral(self, outfile, level, name_='legend'): 475 | level += 1 476 | self.exportLiteralAttributes(outfile, level, [], name_) 477 | if self.hasContent_(): 478 | self.exportLiteralChildren(outfile, level, name_) 479 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 480 | pass 481 | def exportLiteralChildren(self, outfile, level, name_): 482 | showIndent(outfile, level) 483 | outfile.write('statusType=[\n') 484 | level += 1 485 | for statusType_ in self.statusType: 486 | showIndent(outfile, level) 487 | outfile.write('model_.statusType(\n') 488 | statusType_.exportLiteral(outfile, level) 489 | showIndent(outfile, level) 490 | outfile.write('),\n') 491 | level -= 1 492 | showIndent(outfile, level) 493 | outfile.write('],\n') 494 | def build(self, node): 495 | self.buildAttributes(node, node.attrib, []) 496 | for child in node: 497 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 498 | self.buildChildren(child, node, nodeName_) 499 | def buildAttributes(self, node, attrs, already_processed): 500 | pass 501 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 502 | if nodeName_ == 'statusType': 503 | obj_ = statusType.factory() 504 | obj_.build(child_) 505 | self.statusType.append(obj_) 506 | # end class legend 507 | 508 | 509 | class statusType(GeneratedsSuper): 510 | subclass = None 511 | superclass = None 512 | def __init__(self, name=None, description=None, valueOf_=None): 513 | self.name = _cast(None, name) 514 | self.description = _cast(None, description) 515 | self.valueOf_ = valueOf_ 516 | def factory(*args_, **kwargs_): 517 | if statusType.subclass: 518 | return statusType.subclass(*args_, **kwargs_) 519 | else: 520 | return statusType(*args_, **kwargs_) 521 | factory = staticmethod(factory) 522 | def get_name(self): return self.name 523 | def set_name(self, name): self.name = name 524 | def get_description(self): return self.description 525 | def set_description(self, description): self.description = description 526 | def get_valueOf_(self): return self.valueOf_ 527 | def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 528 | def export(self, outfile, level, namespace_='tns:', name_='statusType', namespacedef_=''): 529 | showIndent(outfile, level) 530 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 531 | self.exportAttributes(outfile, level, [], namespace_, name_='statusType') 532 | if self.hasContent_(): 533 | outfile.write('>') 534 | outfile.write(self.valueOf_) 535 | self.exportChildren(outfile, level + 1, namespace_, name_) 536 | outfile.write('\n' % (namespace_, name_)) 537 | else: 538 | outfile.write('/>\n') 539 | def exportAttributes(self, outfile, level, already_processed, namespace_='tns:', name_='statusType'): 540 | if self.name is not None and 'name' not in already_processed: 541 | already_processed.append('name') 542 | outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), )) 543 | if self.description is not None and 'description' not in already_processed: 544 | already_processed.append('description') 545 | outfile.write(' description=%s' % (self.gds_format_string(quote_attrib(self.description).encode(ExternalEncoding), input_name='description'), )) 546 | def exportChildren(self, outfile, level, namespace_='tns:', name_='statusType', fromsubclass_=False): 547 | pass 548 | def hasContent_(self): 549 | if ( 550 | self.valueOf_ 551 | ): 552 | return True 553 | else: 554 | return False 555 | def exportLiteral(self, outfile, level, name_='statusType'): 556 | level += 1 557 | self.exportLiteralAttributes(outfile, level, [], name_) 558 | if self.hasContent_(): 559 | self.exportLiteralChildren(outfile, level, name_) 560 | showIndent(outfile, level) 561 | outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) 562 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 563 | if self.name is not None and 'name' not in already_processed: 564 | already_processed.append('name') 565 | showIndent(outfile, level) 566 | outfile.write('name = "%s",\n' % (self.name,)) 567 | if self.description is not None and 'description' not in already_processed: 568 | already_processed.append('description') 569 | showIndent(outfile, level) 570 | outfile.write('description = "%s",\n' % (self.description,)) 571 | def exportLiteralChildren(self, outfile, level, name_): 572 | pass 573 | def build(self, node): 574 | self.buildAttributes(node, node.attrib, []) 575 | self.valueOf_ = get_all_text_(node) 576 | for child in node: 577 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 578 | self.buildChildren(child, node, nodeName_) 579 | def buildAttributes(self, node, attrs, already_processed): 580 | value = attrs.get('name') 581 | if value is not None and 'name' not in already_processed: 582 | already_processed.append('name') 583 | self.name = value 584 | value = attrs.get('description') 585 | if value is not None and 'description' not in already_processed: 586 | already_processed.append('description') 587 | self.description = value 588 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 589 | pass 590 | # end class statusType 591 | 592 | 593 | class lu(GeneratedsSuper): 594 | subclass = None 595 | superclass = None 596 | def __init__(self, status=None, hasAnnotation=None, name=None, frameID=None, frameName=None, ID=None, valueOf_=None): 597 | self.status = _cast(None, status) 598 | self.hasAnnotation = _cast(bool, hasAnnotation) 599 | self.name = _cast(None, name) 600 | self.frameID = _cast(int, frameID) 601 | self.frameName = _cast(None, frameName) 602 | self.ID = _cast(int, ID) 603 | self.valueOf_ = valueOf_ 604 | def factory(*args_, **kwargs_): 605 | if lu.subclass: 606 | return lu.subclass(*args_, **kwargs_) 607 | else: 608 | return lu(*args_, **kwargs_) 609 | factory = staticmethod(factory) 610 | def get_status(self): return self.status 611 | def set_status(self, status): self.status = status 612 | def get_hasAnnotation(self): return self.hasAnnotation 613 | def set_hasAnnotation(self, hasAnnotation): self.hasAnnotation = hasAnnotation 614 | def get_name(self): return self.name 615 | def set_name(self, name): self.name = name 616 | def get_frameID(self): return self.frameID 617 | def set_frameID(self, frameID): self.frameID = frameID 618 | def get_frameName(self): return self.frameName 619 | def set_frameName(self, frameName): self.frameName = frameName 620 | def get_ID(self): return self.ID 621 | def set_ID(self, ID): self.ID = ID 622 | def get_valueOf_(self): return self.valueOf_ 623 | def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_ 624 | def export(self, outfile, level, namespace_='tns:', name_='lu', namespacedef_=''): 625 | showIndent(outfile, level) 626 | outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) 627 | self.exportAttributes(outfile, level, [], namespace_, name_='lu') 628 | if self.hasContent_(): 629 | outfile.write('>') 630 | outfile.write(self.valueOf_) 631 | self.exportChildren(outfile, level + 1, namespace_, name_) 632 | outfile.write('\n' % (namespace_, name_)) 633 | else: 634 | outfile.write('/>\n') 635 | def exportAttributes(self, outfile, level, already_processed, namespace_='tns:', name_='lu'): 636 | if self.status is not None and 'status' not in already_processed: 637 | already_processed.append('status') 638 | outfile.write(' status=%s' % (self.gds_format_string(quote_attrib(self.status).encode(ExternalEncoding), input_name='status'), )) 639 | if self.hasAnnotation is not None and 'hasAnnotation' not in already_processed: 640 | already_processed.append('hasAnnotation') 641 | outfile.write(' hasAnnotation="%s"' % self.gds_format_boolean(self.gds_str_lower(str(self.hasAnnotation)), input_name='hasAnnotation')) 642 | if self.name is not None and 'name' not in already_processed: 643 | already_processed.append('name') 644 | outfile.write(' name=%s' % (self.gds_format_string(quote_attrib(self.name).encode(ExternalEncoding), input_name='name'), )) 645 | if self.frameID is not None and 'frameID' not in already_processed: 646 | already_processed.append('frameID') 647 | outfile.write(' frameID="%s"' % self.gds_format_integer(self.frameID, input_name='frameID')) 648 | if self.frameName is not None and 'frameName' not in already_processed: 649 | already_processed.append('frameName') 650 | outfile.write(' frameName=%s' % (self.gds_format_string(quote_attrib(self.frameName).encode(ExternalEncoding), input_name='frameName'), )) 651 | if self.ID is not None and 'ID' not in already_processed: 652 | already_processed.append('ID') 653 | outfile.write(' ID="%s"' % self.gds_format_integer(self.ID, input_name='ID')) 654 | def exportChildren(self, outfile, level, namespace_='tns:', name_='lu', fromsubclass_=False): 655 | pass 656 | def hasContent_(self): 657 | if ( 658 | self.valueOf_ 659 | ): 660 | return True 661 | else: 662 | return False 663 | def exportLiteral(self, outfile, level, name_='lu'): 664 | level += 1 665 | self.exportLiteralAttributes(outfile, level, [], name_) 666 | if self.hasContent_(): 667 | self.exportLiteralChildren(outfile, level, name_) 668 | showIndent(outfile, level) 669 | outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) 670 | def exportLiteralAttributes(self, outfile, level, already_processed, name_): 671 | if self.status is not None and 'status' not in already_processed: 672 | already_processed.append('status') 673 | showIndent(outfile, level) 674 | outfile.write('status = "%s",\n' % (self.status,)) 675 | if self.hasAnnotation is not None and 'hasAnnotation' not in already_processed: 676 | already_processed.append('hasAnnotation') 677 | showIndent(outfile, level) 678 | outfile.write('hasAnnotation = %s,\n' % (self.hasAnnotation,)) 679 | if self.name is not None and 'name' not in already_processed: 680 | already_processed.append('name') 681 | showIndent(outfile, level) 682 | outfile.write('name = "%s",\n' % (self.name,)) 683 | if self.frameID is not None and 'frameID' not in already_processed: 684 | already_processed.append('frameID') 685 | showIndent(outfile, level) 686 | outfile.write('frameID = %d,\n' % (self.frameID,)) 687 | if self.frameName is not None and 'frameName' not in already_processed: 688 | already_processed.append('frameName') 689 | showIndent(outfile, level) 690 | outfile.write('frameName = "%s",\n' % (self.frameName,)) 691 | if self.ID is not None and 'ID' not in already_processed: 692 | already_processed.append('ID') 693 | showIndent(outfile, level) 694 | outfile.write('ID = %d,\n' % (self.ID,)) 695 | def exportLiteralChildren(self, outfile, level, name_): 696 | pass 697 | def build(self, node): 698 | self.buildAttributes(node, node.attrib, []) 699 | self.valueOf_ = get_all_text_(node) 700 | for child in node: 701 | nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] 702 | self.buildChildren(child, node, nodeName_) 703 | def buildAttributes(self, node, attrs, already_processed): 704 | value = attrs.get('status') 705 | if value is not None and 'status' not in already_processed: 706 | already_processed.append('status') 707 | self.status = value 708 | value = attrs.get('hasAnnotation') 709 | if value is not None and 'hasAnnotation' not in already_processed: 710 | already_processed.append('hasAnnotation') 711 | if value in ('true', '1'): 712 | self.hasAnnotation = True 713 | elif value in ('false', '0'): 714 | self.hasAnnotation = False 715 | else: 716 | raise_parse_error(node, 'Bad boolean attribute') 717 | value = attrs.get('name') 718 | if value is not None and 'name' not in already_processed: 719 | already_processed.append('name') 720 | self.name = value 721 | value = attrs.get('frameID') 722 | if value is not None and 'frameID' not in already_processed: 723 | already_processed.append('frameID') 724 | try: 725 | self.frameID = int(value) 726 | except ValueError, exp: 727 | raise_parse_error(node, 'Bad integer attribute: %s' % exp) 728 | value = attrs.get('frameName') 729 | if value is not None and 'frameName' not in already_processed: 730 | already_processed.append('frameName') 731 | self.frameName = value 732 | value = attrs.get('ID') 733 | if value is not None and 'ID' not in already_processed: 734 | already_processed.append('ID') 735 | try: 736 | self.ID = int(value) 737 | except ValueError, exp: 738 | raise_parse_error(node, 'Bad integer attribute: %s' % exp) 739 | def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): 740 | pass 741 | # end class lu 742 | 743 | 744 | USAGE_TEXT = """ 745 | Usage: python .py [ -s ] 746 | """ 747 | 748 | def usage(): 749 | print USAGE_TEXT 750 | sys.exit(1) 751 | 752 | 753 | def get_root_tag(node): 754 | tag = Tag_pattern_.match(node.tag).groups()[-1] 755 | rootClass = globals().get(tag) 756 | return tag, rootClass 757 | 758 | 759 | def parse(inFileName): 760 | doc = parsexml_(inFileName) 761 | rootNode = doc.getroot() 762 | rootTag, rootClass = get_root_tag(rootNode) 763 | if rootClass is None: 764 | rootTag = 'luIndex' 765 | rootClass = luIndex 766 | rootObj = rootClass.factory() 767 | rootObj.build(rootNode) 768 | # Enable Python to collect the space used by the DOM. 769 | doc = None 770 | sys.stdout.write('\n') 771 | rootObj.export(sys.stdout, 0, name_=rootTag, 772 | namespacedef_='') 773 | return rootObj 774 | 775 | 776 | def parseString(inString): 777 | from StringIO import StringIO 778 | doc = parsexml_(StringIO(inString)) 779 | rootNode = doc.getroot() 780 | rootTag, rootClass = get_root_tag(rootNode) 781 | if rootClass is None: 782 | rootTag = 'luIndex' 783 | rootClass = luIndex 784 | rootObj = rootClass.factory() 785 | rootObj.build(rootNode) 786 | # Enable Python to collect the space used by the DOM. 787 | doc = None 788 | sys.stdout.write('\n') 789 | rootObj.export(sys.stdout, 0, name_="luIndex", 790 | namespacedef_='') 791 | return rootObj 792 | 793 | 794 | def parseLiteral(inFileName): 795 | doc = parsexml_(inFileName) 796 | rootNode = doc.getroot() 797 | rootTag, rootClass = get_root_tag(rootNode) 798 | if rootClass is None: 799 | rootTag = 'luIndex' 800 | rootClass = luIndex 801 | rootObj = rootClass.factory() 802 | rootObj.build(rootNode) 803 | # Enable Python to collect the space used by the DOM. 804 | doc = None 805 | sys.stdout.write('#from luIndex import *\n\n') 806 | sys.stdout.write('import luIndex as model_\n\n') 807 | sys.stdout.write('rootObj = model_.rootTag(\n') 808 | rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) 809 | sys.stdout.write(')\n') 810 | return rootObj 811 | 812 | 813 | def main(): 814 | args = sys.argv[1:] 815 | if len(args) == 1: 816 | parse(args[0]) 817 | else: 818 | usage() 819 | 820 | 821 | if __name__ == '__main__': 822 | #import pdb; pdb.set_trace() 823 | main() 824 | 825 | 826 | __all__ = [ 827 | "legend", 828 | "lu", 829 | "luIndex", 830 | "statusType" 831 | ] 832 | -------------------------------------------------------------------------------- /1.5/luIndexSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:01:18 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class luIndexSub(supermod.luIndex): 74 | def __init__(self, legend=None, lu=None): 75 | super(luIndexSub, self).__init__(legend, lu, ) 76 | supermod.luIndex.subclass = luIndexSub 77 | # end class luIndexSub 78 | 79 | 80 | class legendSub(supermod.legend): 81 | def __init__(self, statusType=None): 82 | super(legendSub, self).__init__(statusType, ) 83 | supermod.legend.subclass = legendSub 84 | # end class legendSub 85 | 86 | 87 | class statusTypeSub(supermod.statusType): 88 | def __init__(self, name=None, description=None, valueOf_=None): 89 | super(statusTypeSub, self).__init__(name, description, valueOf_, ) 90 | supermod.statusType.subclass = statusTypeSub 91 | # end class statusTypeSub 92 | 93 | 94 | class luSub(supermod.lu): 95 | def __init__(self, status=None, hasAnnotation=None, name=None, frameID=None, frameName=None, ID=None, valueOf_=None): 96 | super(luSub, self).__init__(status, hasAnnotation, name, frameID, frameName, ID, valueOf_, ) 97 | supermod.lu.subclass = luSub 98 | # end class luSub 99 | 100 | 101 | 102 | def get_root_tag(node): 103 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 104 | rootClass = None 105 | if hasattr(supermod, tag): 106 | rootClass = getattr(supermod, tag) 107 | return tag, rootClass 108 | 109 | 110 | def parse(inFilename): 111 | doc = parsexml_(inFilename) 112 | rootNode = doc.getroot() 113 | rootTag, rootClass = get_root_tag(rootNode) 114 | if rootClass is None: 115 | rootTag = 'luIndex' 116 | rootClass = supermod.luIndex 117 | rootObj = rootClass.factory() 118 | rootObj.build(rootNode) 119 | # Enable Python to collect the space used by the DOM. 120 | doc = None 121 | sys.stdout.write('\n') 122 | rootObj.export(sys.stdout, 0, name_=rootTag, 123 | namespacedef_='') 124 | doc = None 125 | return rootObj 126 | 127 | 128 | def parseString(inString): 129 | from StringIO import StringIO 130 | doc = parsexml_(StringIO(inString)) 131 | rootNode = doc.getroot() 132 | rootTag, rootClass = get_root_tag(rootNode) 133 | if rootClass is None: 134 | rootTag = 'luIndex' 135 | rootClass = supermod.luIndex 136 | rootObj = rootClass.factory() 137 | rootObj.build(rootNode) 138 | # Enable Python to collect the space used by the DOM. 139 | doc = None 140 | sys.stdout.write('\n') 141 | rootObj.export(sys.stdout, 0, name_=rootTag, 142 | namespacedef_='') 143 | return rootObj 144 | 145 | 146 | def parseLiteral(inFilename): 147 | doc = parsexml_(inFilename) 148 | rootNode = doc.getroot() 149 | rootTag, rootClass = get_root_tag(rootNode) 150 | if rootClass is None: 151 | rootTag = 'luIndex' 152 | rootClass = supermod.luIndex 153 | rootObj = rootClass.factory() 154 | rootObj.build(rootNode) 155 | # Enable Python to collect the space used by the DOM. 156 | doc = None 157 | sys.stdout.write('#from ??? import *\n\n') 158 | sys.stdout.write('import ??? as model_\n\n') 159 | sys.stdout.write('rootObj = model_.luIndex(\n') 160 | rootObj.exportLiteral(sys.stdout, 0, name_="luIndex") 161 | sys.stdout.write(')\n') 162 | return rootObj 163 | 164 | 165 | USAGE_TEXT = """ 166 | Usage: python ???.py 167 | """ 168 | 169 | def usage(): 170 | print USAGE_TEXT 171 | sys.exit(1) 172 | 173 | 174 | def main(): 175 | args = sys.argv[1:] 176 | if len(args) != 1: 177 | usage() 178 | infilename = args[0] 179 | root = parse(infilename) 180 | 181 | 182 | if __name__ == '__main__': 183 | #import pdb; pdb.set_trace() 184 | main() 185 | 186 | 187 | -------------------------------------------------------------------------------- /1.5/semTypesSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:01:40 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class semTypesSub(supermod.semTypes): 74 | def __init__(self, XMLCreated=None, semType=None): 75 | super(semTypesSub, self).__init__(XMLCreated, semType, ) 76 | supermod.semTypes.subclass = semTypesSub 77 | # end class semTypesSub 78 | 79 | 80 | class semTypeTypeSub(supermod.semTypeType): 81 | def __init__(self, abbrev=None, ID=None, name=None, definition=None, superType=None): 82 | super(semTypeTypeSub, self).__init__(abbrev, ID, name, definition, superType, ) 83 | supermod.semTypeType.subclass = semTypeTypeSub 84 | # end class semTypeTypeSub 85 | 86 | 87 | class superTypeSub(supermod.superType): 88 | def __init__(self, superTypeName=None, supID=None, valueOf_=None): 89 | super(superTypeSub, self).__init__(superTypeName, supID, valueOf_, ) 90 | supermod.superType.subclass = superTypeSub 91 | # end class superTypeSub 92 | 93 | 94 | class lexemeTypeSub(supermod.lexemeType): 95 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 96 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 97 | supermod.lexemeType.subclass = lexemeTypeSub 98 | # end class lexemeTypeSub 99 | 100 | 101 | class semTypeRefTypeSub(supermod.semTypeRefType): 102 | def __init__(self, ID=None, name=None, valueOf_=None): 103 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 104 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 105 | # end class semTypeRefTypeSub 106 | 107 | 108 | 109 | def get_root_tag(node): 110 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 111 | rootClass = None 112 | if hasattr(supermod, tag): 113 | rootClass = getattr(supermod, tag) 114 | return tag, rootClass 115 | 116 | 117 | def parse(inFilename): 118 | doc = parsexml_(inFilename) 119 | rootNode = doc.getroot() 120 | rootTag, rootClass = get_root_tag(rootNode) 121 | if rootClass is None: 122 | rootTag = 'semTypes' 123 | rootClass = supermod.semTypes 124 | rootObj = rootClass.factory() 125 | rootObj.build(rootNode) 126 | # Enable Python to collect the space used by the DOM. 127 | doc = None 128 | sys.stdout.write('\n') 129 | rootObj.export(sys.stdout, 0, name_=rootTag, 130 | namespacedef_='') 131 | doc = None 132 | return rootObj 133 | 134 | 135 | def parseString(inString): 136 | from StringIO import StringIO 137 | doc = parsexml_(StringIO(inString)) 138 | rootNode = doc.getroot() 139 | rootTag, rootClass = get_root_tag(rootNode) 140 | if rootClass is None: 141 | rootTag = 'semTypes' 142 | rootClass = supermod.semTypes 143 | rootObj = rootClass.factory() 144 | rootObj.build(rootNode) 145 | # Enable Python to collect the space used by the DOM. 146 | doc = None 147 | sys.stdout.write('\n') 148 | rootObj.export(sys.stdout, 0, name_=rootTag, 149 | namespacedef_='') 150 | return rootObj 151 | 152 | 153 | def parseLiteral(inFilename): 154 | doc = parsexml_(inFilename) 155 | rootNode = doc.getroot() 156 | rootTag, rootClass = get_root_tag(rootNode) 157 | if rootClass is None: 158 | rootTag = 'semTypes' 159 | rootClass = supermod.semTypes 160 | rootObj = rootClass.factory() 161 | rootObj.build(rootNode) 162 | # Enable Python to collect the space used by the DOM. 163 | doc = None 164 | sys.stdout.write('#from ??? import *\n\n') 165 | sys.stdout.write('import ??? as model_\n\n') 166 | sys.stdout.write('rootObj = model_.semTypes(\n') 167 | rootObj.exportLiteral(sys.stdout, 0, name_="semTypes") 168 | sys.stdout.write(')\n') 169 | return rootObj 170 | 171 | 172 | USAGE_TEXT = """ 173 | Usage: python ???.py 174 | """ 175 | 176 | def usage(): 177 | print USAGE_TEXT 178 | sys.exit(1) 179 | 180 | 181 | def main(): 182 | args = sys.argv[1:] 183 | if len(args) != 1: 184 | usage() 185 | infilename = args[0] 186 | root = parse(infilename) 187 | 188 | 189 | if __name__ == '__main__': 190 | #import pdb; pdb.set_trace() 191 | main() 192 | 193 | 194 | -------------------------------------------------------------------------------- /1.5/sentenceSub.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # Generated Fri Apr 15 16:03:50 2011 by generateDS.py version 2.4c. 5 | # 6 | 7 | import sys 8 | 9 | import ??? as supermod 10 | 11 | etree_ = None 12 | Verbose_import_ = False 13 | ( XMLParser_import_none, XMLParser_import_lxml, 14 | XMLParser_import_elementtree 15 | ) = range(3) 16 | XMLParser_import_library = None 17 | try: 18 | # lxml 19 | from lxml import etree as etree_ 20 | XMLParser_import_library = XMLParser_import_lxml 21 | if Verbose_import_: 22 | print("running with lxml.etree") 23 | except ImportError: 24 | try: 25 | # cElementTree from Python 2.5+ 26 | import xml.etree.cElementTree as etree_ 27 | XMLParser_import_library = XMLParser_import_elementtree 28 | if Verbose_import_: 29 | print("running with cElementTree on Python 2.5+") 30 | except ImportError: 31 | try: 32 | # ElementTree from Python 2.5+ 33 | import xml.etree.ElementTree as etree_ 34 | XMLParser_import_library = XMLParser_import_elementtree 35 | if Verbose_import_: 36 | print("running with ElementTree on Python 2.5+") 37 | except ImportError: 38 | try: 39 | # normal cElementTree install 40 | import cElementTree as etree_ 41 | XMLParser_import_library = XMLParser_import_elementtree 42 | if Verbose_import_: 43 | print("running with cElementTree") 44 | except ImportError: 45 | try: 46 | # normal ElementTree install 47 | import elementtree.ElementTree as etree_ 48 | XMLParser_import_library = XMLParser_import_elementtree 49 | if Verbose_import_: 50 | print("running with ElementTree") 51 | except ImportError: 52 | raise ImportError("Failed to import ElementTree from any known place") 53 | 54 | def parsexml_(*args, **kwargs): 55 | if (XMLParser_import_library == XMLParser_import_lxml and 56 | 'parser' not in kwargs): 57 | # Use the lxml ElementTree compatible parser so that, e.g., 58 | # we ignore comments. 59 | kwargs['parser'] = etree_.ETCompatXMLParser() 60 | doc = etree_.parse(*args, **kwargs) 61 | return doc 62 | 63 | # 64 | # Globals 65 | # 66 | 67 | ExternalEncoding = 'ascii' 68 | 69 | # 70 | # Data representation classes 71 | # 72 | 73 | class sentenceTypeSub(supermod.sentenceType): 74 | def __init__(self, docID=None, sentNo=None, paragNo=None, aPos=None, corpID=None, ID=None, text=None, annotationSet=None): 75 | super(sentenceTypeSub, self).__init__(docID, sentNo, paragNo, aPos, corpID, ID, text, annotationSet, ) 76 | supermod.sentenceType.subclass = sentenceTypeSub 77 | # end class sentenceTypeSub 78 | 79 | 80 | class annotationSetTypeSub(supermod.annotationSetType): 81 | def __init__(self, status=None, cxnID=None, luID=None, frameID=None, cDate=None, frameName=None, luName=None, cxnName=None, ID=None, layer=None): 82 | super(annotationSetTypeSub, self).__init__(status, cxnID, luID, frameID, cDate, frameName, luName, cxnName, ID, layer, ) 83 | supermod.annotationSetType.subclass = annotationSetTypeSub 84 | # end class annotationSetTypeSub 85 | 86 | 87 | class layerTypeSub(supermod.layerType): 88 | def __init__(self, name=None, rank=None, label=None): 89 | super(layerTypeSub, self).__init__(name, rank, label, ) 90 | supermod.layerType.subclass = layerTypeSub 91 | # end class layerTypeSub 92 | 93 | 94 | class labelTypeSub(supermod.labelType): 95 | def __init__(self, itype=None, name=None, bgColor=None, feID=None, start=None, end=None, cBy=None, fgColor=None, valueOf_=None): 96 | super(labelTypeSub, self).__init__(itype, name, bgColor, feID, start, end, cBy, fgColor, valueOf_, ) 97 | supermod.labelType.subclass = labelTypeSub 98 | # end class labelTypeSub 99 | 100 | 101 | class lexemeTypeSub(supermod.lexemeType): 102 | def __init__(self, order=None, headword=None, breakBefore=None, name=None, POS=None, valueOf_=None): 103 | super(lexemeTypeSub, self).__init__(order, headword, breakBefore, name, POS, valueOf_, ) 104 | supermod.lexemeType.subclass = lexemeTypeSub 105 | # end class lexemeTypeSub 106 | 107 | 108 | class semTypeRefTypeSub(supermod.semTypeRefType): 109 | def __init__(self, ID=None, name=None, valueOf_=None): 110 | super(semTypeRefTypeSub, self).__init__(ID, name, valueOf_, ) 111 | supermod.semTypeRefType.subclass = semTypeRefTypeSub 112 | # end class semTypeRefTypeSub 113 | 114 | 115 | 116 | def get_root_tag(node): 117 | tag = supermod.Tag_pattern_.match(node.tag).groups()[-1] 118 | rootClass = None 119 | if hasattr(supermod, tag): 120 | rootClass = getattr(supermod, tag) 121 | return tag, rootClass 122 | 123 | 124 | def parse(inFilename): 125 | doc = parsexml_(inFilename) 126 | rootNode = doc.getroot() 127 | rootTag, rootClass = get_root_tag(rootNode) 128 | if rootClass is None: 129 | rootTag = 'sentenceType' 130 | rootClass = supermod.sentenceType 131 | rootObj = rootClass.factory() 132 | rootObj.build(rootNode) 133 | # Enable Python to collect the space used by the DOM. 134 | doc = None 135 | sys.stdout.write('\n') 136 | rootObj.export(sys.stdout, 0, name_=rootTag, 137 | namespacedef_='') 138 | doc = None 139 | return rootObj 140 | 141 | 142 | def parseString(inString): 143 | from StringIO import StringIO 144 | doc = parsexml_(StringIO(inString)) 145 | rootNode = doc.getroot() 146 | rootTag, rootClass = get_root_tag(rootNode) 147 | if rootClass is None: 148 | rootTag = 'sentenceType' 149 | rootClass = supermod.sentenceType 150 | rootObj = rootClass.factory() 151 | rootObj.build(rootNode) 152 | # Enable Python to collect the space used by the DOM. 153 | doc = None 154 | sys.stdout.write('\n') 155 | rootObj.export(sys.stdout, 0, name_=rootTag, 156 | namespacedef_='') 157 | return rootObj 158 | 159 | 160 | def parseLiteral(inFilename): 161 | doc = parsexml_(inFilename) 162 | rootNode = doc.getroot() 163 | rootTag, rootClass = get_root_tag(rootNode) 164 | if rootClass is None: 165 | rootTag = 'sentenceType' 166 | rootClass = supermod.sentenceType 167 | rootObj = rootClass.factory() 168 | rootObj.build(rootNode) 169 | # Enable Python to collect the space used by the DOM. 170 | doc = None 171 | sys.stdout.write('#from ??? import *\n\n') 172 | sys.stdout.write('import ??? as model_\n\n') 173 | sys.stdout.write('rootObj = model_.sentenceType(\n') 174 | rootObj.exportLiteral(sys.stdout, 0, name_="sentenceType") 175 | sys.stdout.write(')\n') 176 | return rootObj 177 | 178 | 179 | USAGE_TEXT = """ 180 | Usage: python ???.py 181 | """ 182 | 183 | def usage(): 184 | print USAGE_TEXT 185 | sys.exit(1) 186 | 187 | 188 | def main(): 189 | args = sys.argv[1:] 190 | if len(args) != 1: 191 | usage() 192 | infilename = args[0] 193 | root = parse(infilename) 194 | 195 | 196 | if __name__ == '__main__': 197 | #import pdb; pdb.set_trace() 198 | main() 199 | 200 | 201 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Patrick Ye, Dustin Smith 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FrameNet in Python 2 | 3 | I'm now maintaining [Patrick Ye](http://ww2.cs.mu.oz.au/~jingy/)'s Python library for accessing [FrameNet](http://framenet.icsi.berkeley.edu/) data. This version works with FrameNet version 1.3. 4 | 5 | ## Getting Started 6 | 7 | First you must obtain and install the FrameNet XML files, which are free for non-commerical and require an application. Then, you can obtain the Python Library and run: 8 | 9 | python setup.py build 10 | sudo python setup.py install 11 | 12 | Second, you should set your `FRAMENET_HOME` environment variable to point to where you installed and uncompressed FrameNet's XML files. (Alternatively you can edit the `FRAMENET_PATH` constant in `framenet/settings.py`). 13 | 14 | Then you can test your installation by running `python test/importer.py` or by opening a Python shell and typing: 15 | 16 | import framenet 17 | fn = framenet.FrameNet() 18 | 19 | The first time you instantiate the **FrameNet** class, it will parse *all* of the XML files and save pickle objects. You should see: 20 | 21 | Loading the frames ... Framenet not initialized, doing it now 22 | Loading xml for frames ... 23 | 24 | The first time you do this it will take a while, so go have a coffee or celebrate your next birthday. 25 | 26 | # Common Functions 27 | 28 | 29 | * **FrameNet.lookupLexicalUnit(text, part_of_speech)** 30 | 31 | You can look up frames by the **lexical units** (e.g., words) and their parts of speech. For example: 32 | 33 | buy = fn.lookupLexicalUnit('buy','v') 34 | 35 | * **FrameNet.lookupFrame(frame)** 36 | 37 | Also, you can look up [FrameNet frames](http://framenet.icsi.berkeley.edu/index.php?option=com_wrapper&Itemid=113) by their name: 38 | 39 | commerce_frame = fn.lookupFrame('Commerce_buy') 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /framenet/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This is the top-level of the FrameNet-Python library 3 | that imports the commonly used modules 4 | """ 5 | 6 | from framenet import FrameNet, testLU 7 | 8 | 9 | __docformat__ = "markdown" -------------------------------------------------------------------------------- /framenet/frame.py: -------------------------------------------------------------------------------- 1 | from framenet import loadXMLAttributes, getNoneTextChildNodes 2 | 3 | 4 | class Frame(dict): 5 | """ 6 | The frame class 7 | """ 8 | 9 | def __init__(self): 10 | """ 11 | Constructor, doesn't do much. 12 | """ 13 | dict.__init__(self) 14 | 15 | self['definition'] = None 16 | self['fes'] = {} 17 | self['lexunits'] = {} 18 | self['semtypes'] = None 19 | 20 | pass 21 | 22 | 23 | def loadXMLNode(self, frameNode): 24 | """ 25 | """ 26 | 27 | loadXMLAttributes(self, frameNode.attributes) 28 | goodNodes = getNoneTextChildNodes(frameNode) 29 | 30 | for node in goodNodes: 31 | if node.nodeName == 'definition': 32 | if not self.loadFrameDefinition(node): 33 | print >> sys.stderr, 'Unable to read definition node for frame:', self['ID'] 34 | elif node.nodeName == 'fes': 35 | if not self.loadFrameFes(node): 36 | print >> sys.stderr, 'Unable to read a fes node for frame:', self['ID'] 37 | elif node.nodeName == 'lexunits': 38 | if not self.loadFrameLexunits(node): 39 | print >> sys.stderr, 'Unable to read a lexunits node for frame:', self['ID'] 40 | elif node.nodeName == 'semTypes': 41 | if not self.loadFrameSemtypes(node): 42 | print >> sys.stderr, 'Unable to read a semtypes node for frame:', self['ID'] 43 | else: 44 | print >> sys.stderr, 'Have no idea how to deal with node type:', node.nodeName 45 | return False 46 | return True 47 | 48 | 49 | def loadFrameDefinition(self, node): 50 | """ 51 | """ 52 | if len(node.childNodes) == 0: 53 | return True 54 | 55 | try: 56 | self['definition'] = node.childNodes[0].nodeValue 57 | except: 58 | print >> sys.stderr, 'There is no definition!' 59 | return False 60 | 61 | return True 62 | 63 | 64 | def loadFrameFes(self, node): 65 | """ 66 | """ 67 | 68 | feNodes = getNoneTextChildNodes(node) 69 | 70 | fes = {} 71 | 72 | for feNode in feNodes: 73 | fe = self.loadFrameFe(feNode) 74 | 75 | if fe == None: 76 | print >> sys.stderr, 'Got a bad fe' 77 | return False 78 | 79 | fes[fe['ID']] = fe 80 | 81 | return True 82 | 83 | 84 | def loadFrameFe(self, feNode): 85 | """ 86 | """ 87 | 88 | goodNodes = getNoneTextChildNodes(feNode) 89 | 90 | fe = {} 91 | fe = loadXMLAttributes(fe, feNode.attributes) 92 | fe['semtypes'] = {} 93 | 94 | for gn in goodNodes: 95 | if gn.nodeName == 'definition': 96 | if not fe.has_key('definition'): 97 | try: 98 | fe['definition'] = gn.childNodes[0].nodeValue 99 | except: 100 | fe['definition'] = None 101 | else: 102 | print >> sys.stderr, 'Error , fe already have a definition:', fe['definition'] 103 | return None 104 | elif gn.nodeName == 'semTypes': 105 | goodSemTypeNodes = getNoneTextChildNodes(gn) 106 | 107 | for gsn in goodSemTypeNodes: 108 | semType = {} 109 | loadXMLAttributes(semType, gsn.attributes) 110 | fe['semtypes'][semType['ID']] = semType 111 | else: 112 | print >> sys.stderr, 'In loadFrameFe, found this node:', gn.nodeName 113 | return None 114 | 115 | return fe 116 | 117 | 118 | def loadFrameLexunits(self, node): 119 | """ 120 | """ 121 | 122 | goodNodes = getNoneTextChildNodes(node) 123 | 124 | i = 0 125 | for gn in goodNodes: 126 | lu = self.loadFrameLexicalUnit(gn) 127 | 128 | if lu == None: 129 | print >> sys.stderr, 'The lu No.' + str(i), 'is bad' 130 | return False 131 | i += 1 132 | 133 | self['lexunits'][lu['ID']] = lu 134 | 135 | return True 136 | 137 | 138 | def loadFrameLexicalUnit(self, lexunitNode): 139 | """ 140 | """ 141 | 142 | lexunit = {} 143 | 144 | loadXMLAttributes(lexunit, lexunitNode.attributes) 145 | 146 | goodNodes = getNoneTextChildNodes(lexunitNode) 147 | 148 | for gn in goodNodes: 149 | if gn.nodeName == 'definition': 150 | try: 151 | lexunit['definition'] = gn.childNodes[0].nodeValue 152 | except: 153 | lexunit['definition'] = None 154 | elif gn.nodeName == 'annotation': 155 | annoNodes = getNoneTextChildNodes(gn) 156 | anno = {} 157 | for an in annoNodes: 158 | try: 159 | anno[str(an.nodeName)] = an.childNodes[0].nodeValue 160 | try: 161 | n = int(anno[str(an.nodeName)]) 162 | anno[str(an.nodeName)] = n 163 | except: 164 | pass 165 | except: 166 | anno[str(an.nodeName)] = None 167 | print >> sys.stderr, 'Warning!! unable to retrieve', an.nodeName, 'for annotation' 168 | lexunit['annotation'] = anno 169 | elif gn.nodeName == 'lexemes': 170 | goodSemTypeNodes = getNoneTextChildNodes(gn) 171 | lexemes = {} 172 | for gsn in goodSemTypeNodes: 173 | lexeme = {} 174 | loadXMLAttributes(lexeme, gsn.attributes) 175 | # store the actual word 176 | lexeme['lexeme'] = gsn.childNodes[0].nodeValue 177 | lexemes[lexeme['ID']] = lexeme 178 | lexunit['lexeme'] = lexemes 179 | elif gn.nodeName == 'semTypes': 180 | goodSemTypeNodes = getNoneTextChildNodes(gn) 181 | semTypes = {} 182 | for gsn in goodSemTypeNodes: 183 | semType = {} 184 | loadXMLAttributes(semType, gsn.attributes) 185 | semTypes[semType['ID']] = semType 186 | lexunit['semtypes'] = semTypes 187 | else: 188 | print >> sys.stderr, 'Error, encounted the node:', gn.nodeName, 'in', lexunitNode.nodeName, 'lexunit' 189 | return None 190 | return lexunit 191 | 192 | 193 | def loadFrameSemtypes(self, node): 194 | """ 195 | """ 196 | 197 | goodSemTypeNodes = getNoneTextChildNodes(node) 198 | 199 | semTypes = {} 200 | for gsn in goodSemTypeNodes: 201 | semType = {} 202 | loadXMLAttributes(semType, gsn.attributes) 203 | semTypes[semType['ID']] = semType 204 | 205 | self['semtypes'] = semTypes 206 | 207 | return True 208 | 209 | #---------------------------------------------------------------------------- 210 | -------------------------------------------------------------------------------- /framenet/frame_relation.py: -------------------------------------------------------------------------------- 1 | import os.path 2 | import cPickle 3 | import xml 4 | import xml.dom.minidom 5 | 6 | from framenet import loadXMLAttributes, getNoneTextChildNodes 7 | 8 | class FrameRelation(dict): 9 | """ 10 | This class deals with frRelation.xml 11 | """ 12 | 13 | def __init__(self): 14 | """ 15 | Constructor, doesn't do much 16 | """ 17 | 18 | dict.__init__(self) 19 | 20 | self['relation-types'] = {} 21 | 22 | 23 | def loadXML(self, fileName): 24 | """ 25 | """ 26 | 27 | doc = xml.dom.minidom.parse(fileName) 28 | 29 | relationTypeNodes = getNoneTextChildNodes(doc.childNodes[1]) #the actual frame-relation-type nodes 30 | 31 | for rtn in relationTypeNodes: 32 | rt = {} #dictionary for frame-relation-type 33 | loadXMLAttributes(rt, rtn.attributes) 34 | relationNodes = getNoneTextChildNodes(rtn) #the actual frame-relationS nodes 35 | if len(relationNodes) != 1: 36 | print >> sys.stderr, 'Got more than one frame-relations node in type:', rt['name'] 37 | return False 38 | singleRelationNodes = getNoneTextChildNodes(relationNodes[0]) # the actual frame-relation nodes 39 | 40 | singleRelations = {} 41 | i = 0 42 | for srn in singleRelationNodes: 43 | tmp = self.loadSingleRelation(srn) 44 | if tmp == None: 45 | print >> sys.stderr, 'Unable to load relation No.' + str(i), 'for type', rt['name'] 46 | return False 47 | singleRelations[tmp['ID']] = tmp 48 | 49 | rt['frame-relations'] = singleRelations 50 | self['relation-types'][rt['ID']] = rt 51 | 52 | return True 53 | 54 | 55 | def loadSingleRelation(self, relationNode): 56 | """ 57 | """ 58 | 59 | frRelation = {} 60 | 61 | loadXMLAttributes(frRelation, relationNode.attributes) 62 | 63 | feNodes = getNoneTextChildNodes(relationNode) 64 | for fn in feNodes: 65 | tmp = {} 66 | loadXMLAttributes(tmp, fn.attributes) 67 | frRelation[tmp['ID']] = tmp 68 | 69 | return frRelation 70 | 71 | #---------------------------------------------------------------------------- 72 | -------------------------------------------------------------------------------- /framenet/framenet.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | 3 | 4 | def loadXMLAttributes(d, attributes): 5 | for attr in attributes.keys(): 6 | sattr = str(attr) 7 | val = attributes[attr].value 8 | try: 9 | sval = str(val) 10 | if sval.isdigit(): 11 | d[sattr] = int(sval) 12 | else: 13 | d[sattr] = sval 14 | except: 15 | d[sattr] = val 16 | return d 17 | 18 | def getNoneTextChildNodes(xmlNode): 19 | """ 20 | """ 21 | 22 | return filter(lambda x:x.nodeType != x.TEXT_NODE, xmlNode.childNodes) 23 | 24 | def testLU(fileName): 25 | a = LexicalUnit() 26 | 27 | try: 28 | if not a.loadXML(FRAMENET_PATH+"/"+LU_DIR_ENV+"/"+fileName): 29 | print >> sys.stderr, 'loading:', fileName, 'failed' 30 | except: 31 | print >> sys.stderr, 'loading:', fileName, 'failed' 32 | print a.getLexemes() 33 | return a 34 | 35 | 36 | def initialize(): 37 | """ 38 | """ 39 | 40 | fn = FrameNet() 41 | fn.initialize() 42 | 43 | pass 44 | 45 | from lexical_unit import LexicalUnit 46 | from frame import Frame 47 | from frame_relation import FrameRelation 48 | 49 | 50 | class FrameNet(dict): 51 | """ 52 | This the master class for FrameNet 53 | """ 54 | 55 | def __init__(self): 56 | """ 57 | Constructor, loads the frames and the frame relations. 58 | """ 59 | pickledFramePath = FRAMENET_PATH + '/' + PICKLED_FRAME_FILE 60 | pickledFrameRelationPath = FRAMENET_PATH + '/' + PICKLED_FRAME_RELATIONS_FILE 61 | pickledLUPath = FRAMENET_PATH + '/' + PICKLED_LU_FILE 62 | 63 | try: 64 | print >> sys.stderr, 'Loading the frames ...', 65 | frames = cPickle.load(open(pickledFramePath)) 66 | self['frames'] = frames 67 | print >> sys.stderr, 'done' 68 | 69 | print >> sys.stderr, 'Loading the frame relations ...', 70 | frRelations = cPickle.load(open(pickledFrameRelationPath)) 71 | self['frameRelations'] = frRelations 72 | print >> sys.stderr, 'done' 73 | 74 | print >> sys.stderr, 'Loading the lexical units data ...', 75 | luData = cPickle.load(open(pickledLUPath)) 76 | print >> sys.stderr, 'done' 77 | self['luIndex'] = luData 78 | 79 | except: 80 | print >> sys.stderr, 'Framenet not initialized, doing it now' 81 | self.initialize() 82 | print >> sys.stderr, 'Loading the frames ...', 83 | frames = cPickle.load(open(pickledFramePath)) 84 | self['frames'] = frames 85 | print >> sys.stderr, 'done' 86 | 87 | print >> sys.stderr, 'Loading the frame relations ...', 88 | frRelations = cPickle.load(open(pickledFrameRelationPath)) 89 | self['frameRelations'] = frRelations 90 | print >> sys.stderr, 'done' 91 | 92 | print >> sys.stderr, 'Loading the lexical units data ...', 93 | luData = cPickle.load(open(pickledLUPath)) 94 | print >> sys.stderr, 'done' 95 | self['luIndex'] = luData 96 | 97 | self['luCache'] = {} 98 | self._generateFrameIndex() 99 | pass 100 | 101 | 102 | def _generatePickledFrames(self): 103 | """ 104 | Initialises all the frames 105 | """ 106 | 107 | framePath = FRAMENET_PATH+ '/' + FRAME_DIR_ENV + '/' + FRAME_FILE 108 | pickledFramePath = FRAMENET_PATH + '/' + PICKLED_FRAME_FILE 109 | 110 | print >> sys.stderr, 'Loading xml for frames ...', 111 | doc = xml.dom.minidom.parse(framePath) 112 | frameNodes = getNoneTextChildNodes(doc.childNodes[1]) 113 | print >> sys.stderr, 'done', 114 | 115 | frames = {} 116 | print >> sys.stderr, 'parsing each frame ...', 117 | for fn in frameNodes: 118 | f = Frame() 119 | f.loadXMLNode(fn) 120 | frames[f['ID']] = f 121 | print >> sys.stderr, 'done', 122 | 123 | print >> sys.stderr, 'saving the frames ...', 124 | cPickle.dump(frames, open(pickledFramePath, 'w'), cPickle.HIGHEST_PROTOCOL) 125 | print >> sys.stderr, 'done' 126 | 127 | pass 128 | 129 | def _generatePickledFrameRelations(self): 130 | """ 131 | Initialises all the frames 132 | """ 133 | 134 | frRelationPath = FRAMENET_PATH + '/' + FRAME_DIR_ENV + '/' + FRAME_RELATION_FILE 135 | pickledFrameRelationPath = FRAMENET_PATH + '/' + PICKLED_FRAME_RELATIONS_FILE 136 | 137 | print >> sys.stderr, 'Loading xml for frame relations ...', 138 | frRelations = FrameRelation() 139 | frRelations.loadXML(frRelationPath) 140 | print >> sys.stderr, 'done', 141 | 142 | print >> sys.stderr, 'saving the frame relationships ...', 143 | cPickle.dump(frRelations, open(pickledFrameRelationPath, 'w'), cPickle.HIGHEST_PROTOCOL) 144 | print >> sys.stderr, 'done' 145 | 146 | pass 147 | 148 | 149 | def _generatePickledLexicalUnitsIndex(self): 150 | """ 151 | Initialises all the frames 152 | """ 153 | 154 | baseDir = FRAMENET_PATH + '/' + LU_DIR_ENV 155 | pickledLUPath = FRAMENET_PATH + '/' + PICKLED_LU_FILE 156 | 157 | lexicalUnitsIndexByName = {} 158 | for _f in os.listdir(baseDir): 159 | if _f.lower().startswith('lu') and _f.lower().endswith('.xml'): 160 | print >> sys.stderr, 'Loading:', _f, ": ", 161 | lu = LexicalUnit() 162 | lu.loadXML(baseDir + '/' + _f) 163 | print >> sys.stderr, lu['name'], '...', 164 | print >> sys.stderr, 'done' 165 | 166 | if lexicalUnitsIndexByName.has_key(lu['name']): 167 | lexicalUnitsIndexByName[lu['name']][lu['ID']] = 1 168 | else: 169 | lexicalUnitsIndexByName[lu['name']] = {lu['ID']:1} 170 | 171 | print >> sys.stderr, 'Saving the pickled lu files ...', 172 | cPickle.dump(lexicalUnitsIndexByName, open(pickledLUPath, 'w'), cPickle.HIGHEST_PROTOCOL) 173 | print >> sys.stderr, 'done' 174 | pass 175 | 176 | def _generateFrameIndex(self): 177 | """ 178 | Generate an index from frame name to Frame objects 179 | """ 180 | 181 | self['frameIndex'] = {} 182 | 183 | for _id in self['frames'].keys(): 184 | f = self['frames'][_id] 185 | name = f['name'] 186 | if self['frameIndex'].has_key(name): 187 | print >> sys.stderr, 'Error, multiple frame name:', name, 'found' 188 | sys.exit() 189 | 190 | self['frameIndex'][name] = f 191 | 192 | pass 193 | 194 | def initialize(self): 195 | """ 196 | This function should be called only once before the whole thing can be used. 197 | """ 198 | self._generatePickledFrames() 199 | self._generatePickledFrameRelations() 200 | self._generatePickledLexicalUnitsIndex() 201 | 202 | return True 203 | 204 | 205 | def lookupLexicalUnit(self, headWord, pos): 206 | """ 207 | This function will look up a given word by its pos. The word must be already 208 | lemmatised and in lower case. The pos must also be in lower case and it can be 209 | one of the following: 210 | (1) v -- for verb 211 | (2) n -- for noun 212 | (3) a -- for adjective 213 | (4) adv -- for adverb 214 | (5) prep -- for preposition 215 | (6) num -- for numbers 216 | (7) intj -- for interjections 217 | 218 | This function will return a dictionary of lexical units which match the (headWord, pos) 219 | pair. The keys to the dictionary will be the IDs of the lexical units, and the values of 220 | the dictionary will be LexicalUnit objects. 221 | """ 222 | 223 | pickledLUPath = FRAMENET_PATH + '/' + LU_DIR_ENV 224 | 225 | w = headWord + '.' + pos 226 | 227 | if self['luCache'].has_key(w): 228 | return self['luCache'][w] 229 | 230 | if not self['luIndex'].has_key(w): 231 | return {} 232 | 233 | objects = {} 234 | for _id in self['luIndex'][w].keys(): 235 | inputFile = pickledLUPath + '/lu' + str(_id) + '.xml' 236 | lu = LexicalUnit() 237 | lu.loadXML(inputFile) 238 | objects[lu['ID']] = lu 239 | 240 | self['luCache'][w] = objects 241 | return objects 242 | 243 | def getFrameGraph(self, frameText): 244 | import networkx as nx 245 | frame = self.lookupFrame(frameText) 246 | g = nx.DiGraph() 247 | frame_ids = frame.keys() 248 | for relations in self['frameRelations']['relation-types'].values(): 249 | relationName = relations['name'] 250 | superFrameName = relations['superFrameName'] 251 | childFrameName = relations['subFrameName'] 252 | rels = relations['frame-relations'] 253 | print "Loading", relationName, superFrameName, childFrameName 254 | for frame_id in frame_ids: 255 | if True: 256 | #for k,rel in rels.items(): 257 | for k2, rel2 in rels.items(): 258 | if rel2['subFrameName'] == frame['name']: 259 | print rel2 260 | 261 | if rel2['ID'] == frame_id: 262 | print "MATCH ON ID" 263 | print rel2['subFrameName'] 264 | if int(rel2['subId']) == frame_id: 265 | print rel2 266 | elif int(rel2['supId']) == frame_id: 267 | print rel2 268 | 269 | 270 | def lookupFrame(self, frame): 271 | """ 272 | This function takes a string as input, the string should be the name 273 | of the Frame that you want to lookup, and its case sensitive. If not 274 | found, None will be returned. 275 | """ 276 | 277 | if self['frameIndex'].has_key(frame): 278 | return self['frameIndex'][frame] 279 | 280 | return None 281 | 282 | #---------------------------------------------------------------------------- 283 | -------------------------------------------------------------------------------- /framenet/lexical_unit.py: -------------------------------------------------------------------------------- 1 | import os.path 2 | import cPickle 3 | import xml, sys 4 | import xml.dom.minidom 5 | 6 | from framenet import loadXMLAttributes, getNoneTextChildNodes 7 | 8 | class LexicalUnit(dict): 9 | """ 10 | This class is for lexical unit 11 | """ 12 | 13 | def __init__(self): 14 | """ 15 | Initialise the lexical unit. 16 | """ 17 | 18 | dict.__init__(self) 19 | 20 | self['ID'] = None 21 | self['name'] = None 22 | self['pos'] = None 23 | self['definition'] = None 24 | self['frame'] = None 25 | self['incorporatedFE'] = None 26 | 27 | self['lexemes'] = [] 28 | self['subcorpora'] = {} 29 | 30 | self['annotationSets'] = {} 31 | 32 | self['layers'] = {} 33 | 34 | 35 | def getLexemes(self,pos=None): 36 | """ Returns a list of the tokens that evoke this lexical unit, given 37 | an optional pos tag to filter the lexemes by. """ 38 | lex = {} 39 | for l in self['lexemes']: 40 | if pos != None and l['pos'] != pos: continue 41 | lex[l['lexeme']] = l 42 | return lex 43 | 44 | def loadXML(self, fileName): 45 | """ 46 | Load an xml file. 47 | """ 48 | try: 49 | doc = xml.dom.minidom.parse(fileName) 50 | except: 51 | print >> sys.stderr, 'Unable to parse the xml document:', fileName 52 | return False 53 | 54 | # Load the main attributes of the lexunit-annotation nodes 55 | self.loadMainAttributes(doc.childNodes[1]) 56 | 57 | # Then filter out all the useless text nodes 58 | goodNodes = filter(lambda x:x.nodeType != x.TEXT_NODE, doc.childNodes[1].childNodes) 59 | 60 | for node in goodNodes: 61 | if node.nodeName == 'definition': 62 | if not self.loadDefinition(goodNodes[0]): 63 | print >> sys.stderr, '> Failed to load the definition node for document:', fileName 64 | return False 65 | elif node.nodeName == 'subcorpus': 66 | if not self.loadSubcorpus(node): 67 | print >> sys.stderr, '> Failed to load the subcorpus node for document:', fileName 68 | return False 69 | elif node.nodeName == 'lexemes': 70 | if not self.loadLexemes(node): 71 | print >> sys.stderr, '> Failed to load the lexemes node for document:', fileName 72 | return False 73 | return True 74 | 75 | 76 | def loadMainAttributes(self, doc): 77 | """ 78 | Loads the ID, name, frame, POS and incorporateFE attributes of the main document node 79 | """ 80 | 81 | # Load the ID 82 | if doc.attributes.has_key('ID'): 83 | self['ID'] = int(doc.attributes['ID'].value) 84 | else: 85 | print >> sys.stderr, '>> Unable to load the ID node' 86 | return False 87 | 88 | # Load the HeadWord 89 | if doc.attributes.has_key('name'): 90 | n = doc.attributes['name'].value 91 | self['name'] = str(n) 92 | else: 93 | print >> sys.stderr, '>> Unable to load the name' 94 | return False 95 | 96 | # Load the POS 97 | if doc.attributes.has_key('pos'): 98 | self['pos'] = str(doc.attributes['pos'].value) 99 | else: 100 | print >> sys.stderr, '>> Unable to load the POS' 101 | return False 102 | 103 | # Load the frame 104 | if doc.attributes.has_key('frame'): 105 | self['frame'] = str(doc.attributes['frame'].value) 106 | else: 107 | print >> sys.stderr, '>> Unable to load the frame' 108 | return False 109 | 110 | # Load the incorporatedFE 111 | if doc.attributes.has_key('incorporatedFE'): 112 | self['incorporatedFE'] = str(doc.attributes['incorporatedFE'].value) 113 | else: 114 | print >> sys.stderr, '>> Unable to load the incorporatedFE' 115 | return False 116 | 117 | return True 118 | 119 | 120 | def loadDefinition(self, defNode): 121 | """ 122 | Loads the definition node 123 | """ 124 | if len(defNode.childNodes) > 0: 125 | try: 126 | self['definition'] = defNode.childNodes[0].nodeValue 127 | except: 128 | print >> sys.stderr, '>> Unable to load the definition node of:', defNode 129 | return False 130 | return True 131 | 132 | 133 | def loadLexemes(self, lexemeNodes): 134 | """ 135 | Loads the lexemes 136 | """ 137 | 138 | lexemeChildNodes = filter(lambda x:x.nodeType != x.TEXT_NODE, lexemeNodes.childNodes) 139 | 140 | # initialize default list 141 | self['lexemes'] = [] 142 | 143 | for lexemeNode in lexemeChildNodes: 144 | lexeme = {} 145 | try: 146 | lexeme['lexeme'] = lexemeNode.childNodes[0].nodeValue 147 | except: 148 | print >> sys.stderr, '>> Unable to load the lexemeNode lexeme:', lexemeNode 149 | return False 150 | try: 151 | lexeme['ID'] = int(lexemeNode.attributes['ID'].value) 152 | except: 153 | print >> sys.stderr, '>> Unable to read the lexemeNode id' 154 | return False 155 | try: 156 | lexeme['pos'] = str(lexemeNode.attributes['pos'].value) 157 | except: 158 | print >> sys.stderr, '>> Unable to read the lexemeNode pos' 159 | return False 160 | try: 161 | lexeme['breakBefore'] = bool(lexemeNode.attributes['breakBefore'].value) 162 | except: 163 | print >> sys.stderr, '>> Unable to read the lexemeNode breakBefore' 164 | return False 165 | try: 166 | lexeme['headword'] = bool(lexemeNode.attributes['headword'].value) 167 | except: 168 | print >> sys.stderr, '>> Unable to read the lexemeNode headword' 169 | return False 170 | self['lexemes'].append(lexeme) 171 | 172 | return True 173 | 174 | 175 | def loadSubcorpus(self, subCorpusNode): 176 | """ 177 | Loads the subcorpus node 178 | """ 179 | 180 | try: 181 | corpusName = str(subCorpusNode.attributes['name'].value) 182 | except: 183 | print >> sys.stderr, '>> Unable to load the name of the subcorpus node', 184 | return False 185 | 186 | self['subcorpora'][corpusName] = {} 187 | 188 | annotationNodes = filter(lambda x:x.nodeType != x.TEXT_NODE, subCorpusNode.childNodes) 189 | 190 | for annoNode in annotationNodes: 191 | if not self.loadAnnotationSet(annoNode, corpusName): 192 | print >> sys.stderr, '>> Unable to load an annotation set' 193 | return False 194 | return True 195 | 196 | 197 | def loadAnnotationSet(self, annoNode, corpusName): 198 | """ 199 | Loads annotation set. 200 | """ 201 | annotation = {} 202 | try: 203 | annotation['ID'] = int(annoNode.attributes['ID'].value) 204 | except: 205 | print >> sys.stderr, '>>> Unable to read the annoNode id' 206 | return False 207 | 208 | try: 209 | annotation['status'] = str(annoNode.attributes['status'].value) 210 | except: 211 | print >> sys.stderr, '>>> Unable to read the annoNode status' 212 | return False 213 | 214 | goodNodes = filter(lambda x:x.nodeType != x.TEXT_NODE, annoNode.childNodes) 215 | 216 | for node in goodNodes: 217 | if node.nodeName == 'layers': 218 | if annotation.has_key('layers'): 219 | print >> sys.stderr, '>>>> Already has a Layers key!' 220 | return False 221 | elif not self.loadLayers(node, annotation): 222 | return False 223 | elif node.nodeName == 'sentence': 224 | if annotation.has_key('sentence'): 225 | print >> sys.stderr, '>>>> Already has a sentences key!' 226 | return False 227 | elif not self.loadSentence(node, annotation): 228 | return False 229 | 230 | self['annotationSets'][annotation['ID']] = annotation 231 | return True 232 | 233 | 234 | def loadLayers(self, layersNode, annotation): 235 | """ 236 | Loads the layers 237 | """ 238 | 239 | layers = filter(lambda x:x.nodeType != x.TEXT_NODE, layersNode.childNodes) 240 | 241 | singleLayers = {} 242 | 243 | for layer in layers: 244 | loaded = self.loadSingleLayer(layer) 245 | 246 | if loaded == None: 247 | print >> sys.stderr, '>>> Unable to load a layer!' 248 | return False 249 | singleLayers[loaded['ID']] = loaded 250 | 251 | annotation['layers'] = singleLayers 252 | 253 | return True 254 | 255 | 256 | def loadSentence(self, sentNode, annotation): 257 | """ 258 | Loads the sentence 259 | """ 260 | goodNodes = filter(lambda x:x.nodeType != x.TEXT_NODE, sentNode.childNodes) 261 | 262 | if len(goodNodes) != 1: 263 | print >> sys.stderr, '>> Sent node has:', len(goodNodes), 'good nodes' 264 | return False 265 | 266 | sent = {} 267 | try: 268 | sent = loadXMLAttributes(sent, sentNode.attributes) 269 | except: 270 | print >> sys.stderr, '>> Unable to get one of ID or aPos' 271 | return False 272 | 273 | sent['text'] = goodNodes[0].childNodes[0].nodeValue 274 | 275 | if not isinstance(sent['text'], unicode): 276 | print >> sys.stderr, '>> Unable to get the sentence text from', goodNodes[0].childNodes[0] 277 | return False 278 | 279 | try: 280 | sent['text'] = str(sent['text']) 281 | except: 282 | pass 283 | 284 | annotation['sentence'] = sent 285 | 286 | return True 287 | 288 | 289 | def loadSingleLayer(self, layerNode): 290 | """ 291 | Loads a single layer, 292 | """ 293 | 294 | layer = {'labels':{}} 295 | try: 296 | layer['ID'] = int(layerNode.attributes['ID'].value) 297 | layer['name'] = str(layerNode.attributes['name'].value) 298 | except: 299 | print >> sys.stderr, '>> Unable to load layer id or name' 300 | return None 301 | 302 | labelsNode = filter(lambda x:x.nodeType != x.TEXT_NODE, layerNode.childNodes) 303 | 304 | if len(labelsNode) > 1: 305 | print >> sys.stderr, '>> Got more than one labels node for a layer' 306 | print >> sys.stderr, labelsNode 307 | return None 308 | 309 | if len(labelsNode) > 0: 310 | labels = filter(lambda x:x.nodeType != x.TEXT_NODE, labelsNode[0].childNodes) 311 | 312 | for l in labels: 313 | ll = {} 314 | 315 | ll = loadXMLAttributes(ll, l.attributes) 316 | 317 | layer['labels'][ll['ID']] = ll 318 | 319 | self['layers'][layer['ID']] = layer 320 | return layer 321 | -------------------------------------------------------------------------------- /framenet/settings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ FrameNet-Python is a library for reading and accessing FrameNet data. 4 | It was created by Patrick Ye and is maintained by Dustin Smith. For more 5 | information, see: http://github.com/dasmith/FrameNet-python 6 | 7 | This Python library is covered under the MIT/Expat license. FrameNet data 8 | must be obtained separately and is subject to a different license: 9 | http://framenet.icsi.berkeley.edu/ 10 | """ 11 | 12 | VERSION = "1.3a" 13 | 14 | import sys 15 | import os 16 | import os.path 17 | import cPickle 18 | import xml 19 | import xml.dom.minidom 20 | 21 | LU_DIR_ENV = 'luXML' 22 | FRAME_DIR_ENV = 'frXML' 23 | FRAME_FILE = 'frames.xml' 24 | FRAME_RELATION_FILE = 'frRelation.xml' 25 | 26 | PICKLED_FRAME_FILE = 'frames.pickled' 27 | PICKLED_FRAME_RELATIONS_FILE = 'frRelation.pickled' 28 | PICKLED_LU_FILE='lu.pickled' 29 | 30 | pth = os.environ.get('FRAMENET_HOME') 31 | if pth != None: 32 | FRAMENET_PATH = pth 33 | else: 34 | # try the default 35 | FRAMENET_PATH = "/usr/share/framenet1.3" 36 | 37 | print FRAMENET_PATH+"/"+FRAME_DIR_ENV+"/"+FRAME_FILE 38 | if not (os.path.exists(FRAMENET_PATH+"/"+PICKLED_FRAME_FILE) or os.path.exists(FRAMENET_PATH+"/"+FRAME_DIR_ENV+"/"+FRAME_FILE)): 39 | raise Exception("Error, could not open data directory. Set environment variable, FRAMENET_HOME, to data path.") 40 | 41 | def initialize(): 42 | """ 43 | """ 44 | 45 | fn = FrameNet() 46 | fn.initialize() 47 | 48 | #---------------------------------------------------------------------------- 49 | 50 | if __name__ == '__main__': 51 | initialize() 52 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup, Extension 2 | from distutils.unixccompiler import * 3 | from distutils.sysconfig import * 4 | import sys 5 | import os 6 | 7 | setup(name='framenet', 8 | version='1.3a', 9 | packages=['framenet'], 10 | ext_modules = [], 11 | ) 12 | 13 | # The code below is for checking to see if the framenet data files 14 | # exist. It first looks for the files at the path defined 15 | # by the environment variable FRAMENET_HOME. If this is 16 | # undefined, it prompts the user to enter their own path 17 | # or accept the default path, /usr/share/framenet1.3, to 18 | # search for the files. 19 | # 20 | # It will not install unless the files are available, since 21 | # the library is useless without them. 22 | # 23 | # Finally, it asks the user to permanently add the FRAMENET_HOME 24 | # variable to their default shell. (What to do for Windows 25 | # machines?) 26 | 27 | frameNetFiles = ['luXML','frXML','frXML/frames.xml', 'frXML/frRelation.xml'] 28 | 29 | frameNetPath = os.environ.get('FRAMENET_HOME') 30 | if frameNetPath == None: 31 | frameNetPath = "/usr/share/framenet1.3" 32 | entry = raw_input("Please enter the directory where you store FrameNet\ 33 | data [default=%s]: " % (frameNetPath)) 34 | if entry.strip() != "": 35 | frameNetPath = entry.strip() 36 | for fnFile in frameNetFiles: 37 | print "Checking for file %s/%s..." % (frameNetPath,fnFile), 38 | if os.path.exists("%s/%s" % (frameNetPath,fnFile)): 39 | print "OK!" 40 | else: 41 | print "FAILED" 42 | print "Please obtain FrameNet data and set your path properly." 43 | sys.exit(1) 44 | # set environmental variable 45 | os.putenv('FRAMENET_HOME',frameNetPath) 46 | 47 | print "-"*100 48 | print "Please add environment variable FRAMENET_HOME to your shell file. e.g." 49 | print 'echo "FRAMENET_HOME=%s" >> ~/.bashrc ' % (frameNetPath) 50 | print "-"*100 51 | 52 | -------------------------------------------------------------------------------- /test/importer.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | from framenet import * 3 | 4 | 5 | print "Testing framenet import" 6 | fn = framenet.FrameNet() 7 | 8 | print "Printing fn's methods" 9 | 10 | print dir(fn) 11 | 12 | buy = fn.lookupLexicalUnit('buy','v') 13 | print buy 14 | 15 | cb = fn.lookupFrame('Commerce_buy') 16 | 17 | fg = fn.getFrameGraph('Commerce_buy') --------------------------------------------------------------------------------