sobjects/textparsers.py
changeset 8748 f5027f8d2478
parent 7815 2a164a9cf81c
equal deleted inserted replaced
8747:c0d4244e5abc 8748:f5027f8d2478
    24 
    24 
    25 __docformat__ = "restructuredtext en"
    25 __docformat__ = "restructuredtext en"
    26 
    26 
    27 import re
    27 import re
    28 
    28 
    29 from cubicweb import UnknownEid, typed_eid
    29 from cubicweb import UnknownEid
    30 from cubicweb.view import Component
    30 from cubicweb.view import Component
    31 
    31 
    32 
    32 
    33 class TextAnalyzer(Component):
    33 class TextAnalyzer(Component):
    34     """analyze and extract information from plain text by calling registered
    34     """analyze and extract information from plain text by calling registered
    64     instr_rgx = re.compile(':(\w+):\s*#?(\d+)', re.U)
    64     instr_rgx = re.compile(':(\w+):\s*#?(\d+)', re.U)
    65 
    65 
    66     def parse(self, caller, text):
    66     def parse(self, caller, text):
    67         for trname, eid in self.instr_rgx.findall(text):
    67         for trname, eid in self.instr_rgx.findall(text):
    68             try:
    68             try:
    69                 entity = self._cw.entity_from_eid(typed_eid(eid))
    69                 entity = self._cw.entity_from_eid(int(eid))
    70             except UnknownEid:
    70             except UnknownEid:
    71                 self.error("can't get entity with eid %s", eid)
    71                 self.error("can't get entity with eid %s", eid)
    72                 continue
    72                 continue
    73             if not hasattr(entity, 'in_state'):
    73             if not hasattr(entity, 'in_state'):
    74                 self.error('bad change state instruction for eid %s', eid)
    74                 self.error('bad change state instruction for eid %s', eid)