コード例 #1
0
 def _handleLxmlConfigNode(self, session, node):
     if (node.tag == "cluster"):
         maps = []
         for child in node.iterchildren(tag=etree.Element):
             if (child.tag == "map"):
                 t = child.attrib.get('type', '')
                 map = []
                 for xpchild in child.iterchildren(tag=etree.Element):
                     if (xpchild.tag == "xpath"):
                         map.append(flattenTexts(xpchild).strip())
                     elif (xpchild.tag == "process"):
                         # turn xpath chain to workflow
                         ref = xpchild.attrib.get('ref', None)
                         if ref is not None:
                             process = self.get_object(session, ref)
                         else:
                             xpchild.tag = 'workflow'
                             process = CachingWorkflow(session, xpchild, self)
                             process._handleLxmlConfigNode(session, xpchild)
                         map.append(process)
                
                 #vxp = [map[0]]
                 if (len(map) < 3):
                     # default ExactExtractor
                     map.append([['extractor', 'SimpleExtractor']])
                 if (t == u'key'):
                     self.keyMap = [map[0], map[1], map[2]]
                 else:
                     maps.append([map[0], map[1], map[2]])
         self.maps = maps
コード例 #2
0
    def _handleLxmlConfigNode(self, session, node):
        if (node.tag == "cluster"):
            maps = []
            for child in node.iterchildren(tag=etree.Element):
                if (child.tag == "map"):
                    t = child.attrib.get('type', '')
                    map = []
                    for xpchild in child.iterchildren(tag=etree.Element):
                        if (xpchild.tag == "xpath"):
                            map.append(flattenTexts(xpchild).strip())
                        elif (xpchild.tag == "process"):
                            # turn xpath chain to workflow
                            ref = xpchild.attrib.get('ref', None)
                            if ref is not None:
                                process = self.get_object(session, ref)
                            else:
                                xpchild.tag = 'workflow'
                                process = CachingWorkflow(
                                    session, xpchild, self)
                                process._handleLxmlConfigNode(session, xpchild)
                            map.append(process)

                    #vxp = [map[0]]
                    if (len(map) < 3):
                        # default ExactExtractor
                        map.append([['extractor', 'SimpleExtractor']])
                    if (t == u'key'):
                        self.keyMap = [map[0], map[1], map[2]]
                    else:
                        maps.append([map[0], map[1], map[2]])
            self.maps = maps
コード例 #3
0
 def _handleConfigNode(self, session, node):
     if (node.localName == "cluster"):
         maps = []
         for child in node.childNodes:
             if (child.nodeType == elementType
                     and child.localName == "map"):
                 t = child.getAttributeNS(None, 'type')
                 map = []
                 for xpchild in child.childNodes:
                     if (xpchild.nodeType == elementType
                             and xpchild.localName == "xpath"):
                         map.append(flattenTexts(xpchild))
                     elif (xpchild.nodeType == elementType
                           and xpchild.localName == "process"):
                         # turn xpath chain to workflow
                         ref = xpchild.getAttributeNS(None, 'ref')
                         if ref:
                             process = self.get_object(session, ref)
                         else:
                             try:
                                 xpchild.localName = 'workflow'
                             except:
                                 # 4suite dom sets read only
                                 newTop = xpchild.ownerDocument.createElementNS(
                                     None, 'workflow')
                                 for kid in xpchild.childNodes:
                                     newTop.appendChild(kid)
                                 xpchild = newTop
                             process = CachingWorkflow(
                                 session, xpchild, self)
                             process._handleConfigNode(session, xpchild)
                         map.append(process)
                 # XXX FIX ME
                 # vxp = verifyXPaths([map[0]])
                 vxp = [map[0]]
                 if (len(map) < 3):
                     # default ExactExtractor
                     map.append([['extractor', 'SimpleExtractor']])
                 if (t == u'key'):
                     self.keyMap = [vxp[0], map[1], map[2]]
                 else:
                     maps.append([vxp[0], map[1], map[2]])
         self.maps = maps
コード例 #4
0
 def _handleConfigNode(self, session, node):
     if (node.localName == "cluster"):
         maps = []
         for child in node.childNodes:
             if (child.nodeType == elementType and child.localName == "map"):
                 t = child.getAttributeNS(None, 'type')
                 map = []
                 for xpchild in child.childNodes:
                     if (xpchild.nodeType == elementType and xpchild.localName == "xpath"):
                         map.append(flattenTexts(xpchild))
                     elif (xpchild.nodeType == elementType and xpchild.localName == "process"):
                         # turn xpath chain to workflow
                         ref = xpchild.getAttributeNS(None, 'ref')
                         if ref:
                             process = self.get_object(session, ref)
                         else:
                             try:
                                 xpchild.localName = 'workflow'
                             except:
                                 # 4suite dom sets read only
                                 newTop = xpchild.ownerDocument.createElementNS(None, 'workflow')
                                 for kid in xpchild.childNodes:
                                     newTop.appendChild(kid)
                                 xpchild = newTop
                             process = CachingWorkflow(session, xpchild, self)
                             process._handleConfigNode(session, xpchild)
                         map.append(process)
                 # XXX FIX ME 
                 # vxp = verifyXPaths([map[0]])
                 vxp = [map[0]]
                 if (len(map) < 3):
                     # default ExactExtractor
                     map.append([['extractor', 'SimpleExtractor']])
                 if (t == u'key'):
                     self.keyMap = [vxp[0], map[1], map[2]]
                 else:
                     maps.append([vxp[0], map[1], map[2]])
         self.maps = maps
コード例 #5
0
    def _handleLxmlConfigNode(self, session, node):
        # Source
        if (node.tag == "source"):
            key = node.attrib.get('id', None)
            default = node.attrib.get('default', None)
            process = None
            preprocess = None
            xp = None
            for child in node.iterchildren(tag=etree.Element):
                if child.tag == "xpath":
                    if xp == None:
                        ref = child.attrib.get('ref', '')
                        if ref:
                            xp = self.get_object(session, ref)
                        else:
                            node.set('id', self.id + '-xpath')
                            xp = SimpleXPathProcessor(session, node, self)
                            xp._handleLxmlConfigNode(session, node)
                elif child.tag == "preprocess":
                    # turn preprocess chain to workflow
                    ref = child.attrib.get('ref', '')
                    if ref:
                        preprocess = self.get_object(session, ref)
                    else:
                        # create new element
                        e = etree.XML(etree.tostring(child))
                        e.tag = 'workflow'
                        e.set('id', self.id + "-preworkflow")
                        preprocess = CachingWorkflow(session, child, self)
                        preprocess._handleLxmlConfigNode(session, child)
                elif child.tag == "process":
                    # turn xpath chain to workflow
                    ref = child.attrib.get('ref', '')
                    if ref:
                        process = self.get_object(session, ref)
                    else:
                        # create new element
                        e = etree.XML(etree.tostring(child))
                        e.tag = 'workflow'
                        e.set('id', self.id + "-workflow")
                        process = CachingWorkflow(session, e, self)
                        process._handleLxmlConfigNode(session, e)

            self.sources[key] = {
                'source': (xp, process, preprocess),
                'default': default
            }
コード例 #6
0
ファイル: preParser.py プロジェクト: ReinSi/cheshire3
 def _handleLxmlConfigNode(self, session, node):
     # Source
     if (node.tag in ['source', '{%s}source' % CONFIG_NS]):
         key = node.attrib.get('id', None)
         default = node.attrib.get('default', None)
         process = None
         preprocess = None
         xp = None
         for child in node.iterchildren(tag=etree.Element):
             if child.tag in ['xpath', '{%s}xpath' % CONFIG_NS]:
                 if xp is None:
                     ref = child.attrib.get('ref', '')
                     if ref:
                         xp = self.get_object(session, ref)
                     else:
                         node.set('id', self.id + '-xpath')
                         xp = SimpleXPathProcessor(session, node, self)
                         xp._handleLxmlConfigNode(session, node)
             elif child.tag in ['preprocess', '{%s}preprocess' % CONFIG_NS]:
                 # turn preprocess chain to workflow
                 ref = child.attrib.get('ref', '')
                 if ref:
                     preprocess = self.get_object(session, ref)
                 else:
                     # create new element
                     e = etree.XML(etree.tostring(child))
                     e.tag = 'workflow'
                     e.set('id', self.id + "-preworkflow")
                     preprocess = CachingWorkflow(session, child, self)
                     preprocess._handleLxmlConfigNode(session, child)
             elif child.tag in ["process", '{%s}process' % CONFIG_NS]:
                 # turn xpath chain to workflow
                 ref = child.attrib.get('ref', '')
                 if ref:
                     process = self.get_object(session, ref)
                 else:
                     # create new element
                     e = etree.XML(etree.tostring(child))
                     e.tag = 'workflow'
                     e.set('id', self.id + "-workflow")
                     process = CachingWorkflow(session, e, self)
                     process._handleLxmlConfigNode(session, e)
                     
         self.sources[key] = {'source': (xp, process, preprocess), 'default': default}
コード例 #7
0
    def _handleLxmlConfigNode(self, session, node):
        # Source
        if node.tag == "source":
            key = node.attrib.get("id", None)
            default = node.attrib.get("default", None)
            process = None
            preprocess = None
            xp = None
            for child in node.iterchildren(tag=etree.Element):
                if child.tag == "xpath":
                    if xp == None:
                        ref = child.attrib.get("ref", "")
                        if ref:
                            xp = self.get_object(session, ref)
                        else:
                            node.set("id", self.id + "-xpath")
                            xp = SimpleXPathProcessor(session, node, self)
                            xp._handleLxmlConfigNode(session, node)
                elif child.tag == "preprocess":
                    # turn preprocess chain to workflow
                    ref = child.attrib.get("ref", "")
                    if ref:
                        preprocess = self.get_object(session, ref)
                    else:
                        # create new element
                        e = etree.XML(etree.tostring(child))
                        e.tag = "workflow"
                        e.set("id", self.id + "-preworkflow")
                        preprocess = CachingWorkflow(session, child, self)
                        preprocess._handleLxmlConfigNode(session, child)
                elif child.tag == "process":
                    # turn xpath chain to workflow
                    ref = child.attrib.get("ref", "")
                    if ref:
                        process = self.get_object(session, ref)
                    else:
                        # create new element
                        e = etree.XML(etree.tostring(child))
                        e.tag = "workflow"
                        e.set("id", self.id + "-workflow")
                        process = CachingWorkflow(session, e, self)
                        process._handleLxmlConfigNode(session, e)

            self.sources[key] = {"source": (xp, process, preprocess), "default": default}