That <TypeDefinition object '...' at ...>
is just the representation of the in-memory object. If you want to see what the TDL looks like, use tdl.format()
(or just look in the original TDL file):
>>> from delphin import tdl
>>> entries = {obj.identifier: obj for event, obj, _ in tdl.iterparse('~/delphin/jacy/lexicon.tdl') if event == 'TypeDefinition'}
>>> obj = entries['zuzou_n1']
>>> print(tdl.format(obj))
zuzou_n1 := ordinary-nohon-n-lex &
[ STEM < "図像" >,
SYNSEM.LKEYS.KEYREL.PRED "_zuzou_n_1_rel",
TRAITS native_token_list ].
If you want to get the value of a feature, the TypeDefinition object no longer has a get()
method. Instead, it is on the Conjunction object which you can get from obj.conjunction
:
>>> obj.get('STEM') # does not work
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'TypeDefinition' object has no attribute 'get'
>>> obj.conjunction.get('STEM') # use this instead
<ConsList object at 140447975437248>
>>> obj.conjunction.get('SYNSEM.LKEYS.KEYREL.PRED') # path to predicate
<String object (_zuzou_n_1_rel) at 140447740392080>
A ConsList object is just a special type of AVM, and you can use the feature names to get the values of the list:
>>> stems = obj.conjunction.get('STEM')
>>> stems.features()
[('FIRST', <String object (図像) at 140447740391968>), ('REST', None)]
>>> stems.get('FIRST')
<String object (図像) at 140447740391968>
But it may be easier to use the ConsList.values() function, which traverses the features to assemble the values as a Python list:
>>> stems.values()
[<String object (図像) at 140447740391968>]
Now these String objects are low-level TDL types and are actually a subclass of Python’s native str
type, so you can use it like a string, but if you want or need a basic string you can cast it:
>>> str(stems.values()[0])
'図像'