Sha256: d4673b4150847ba253b80e02eda8bca2d1d4c82660899b2eecf557790f1bbf8e

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

# Modified for KAF/NAF

from lxml import etree
from lxml.objectify import dump

class Ctarget:
    def __init__(self,node=None):
        self.type = 'NAF/KAF'
        if node is None:
            self.node = etree.Element('target')
        else:
            self.node = node
            
    def get_id(self):
        return self.node.get('id')
    
    def set_id(self,this_id):
        self.node.set('id',this_id)
        
    def get_node(self):
        return self.node


class Cspan:
    def __init__(self,node=None):
        self.type = 'NAF/KAF'
        if node is None:
            self.node = etree.Element('span')
        else:
            self.node = node
             
    def add_target_id(self,this_id):
        new_target = Ctarget()
        new_target.set_id(this_id)
        self.node.append(new_target.get_node())
             
    def create_from_ids(self,list_ids):
        for this_id in list_ids:
            new_target = Ctarget()
            new_target.set_id(this_id)
            self.node.append(new_target.get_node())
            
    def add_target(self,target):
        self.node.append(target.get_node())
                   

    def __get_target_nodes(self):
        for target_node in self.node.findall('target'):
            yield target_node
    
    def __iter__(self):
        for target_node in self.__get_target_nodes():
            yield Ctarget(target_node)
            
    def get_span_ids(self):
        return [t_obj.get_id() for t_obj in self]
    
    def __str__(self):
        return dump(self.node)
    
    def get_node(self):
        return self.node
                                            

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
opener-opinion-detector-base-2.0.1 core/site-packages/pre_build/KafNafParser/span_data.py
opener-kaf-naf-parser-1.0.1 core/site-packages/pre_build/KafNafParser/span_data.py
opener-kaf-naf-parser-1.0.0 core/site-packages/pre_build/KafNafParser/span_data.py
opener-opinion-detector-base-2.0.0 core/site-packages/pre_build/KafNafParser/span_data.py