Module nafparserpy.layers.chunks
Expand source code
from dataclasses import dataclass
from typing import List
from nafparserpy.layers.utils import create_node, AttributeGetter
@dataclass
class Chunk(AttributeGetter):
    """Represents a chunk"""
    id: str
    head: str
    phrase: str
    attrs: dict
    """optional attributes: 'case'"""
    def __post_init__(self):
        """Copy compulsory attributes to `attrs` field"""
        self.attrs.update({'id': self.id, 'head': self.head, 'phrase': self.phrase})
    def node(self):
        """Create etree node from object"""
        return create_node('chunk', None, [], self.attrs)
    @staticmethod
    def object(node):
        """Create object from etree node"""
        return Chunk(node.get('id'), node.get('head'), node.get('phrase'), node.attrib)
@dataclass
class Chunks:
    """Chunks layer class"""
    items: List[Chunk]
    def node(self):
        """Create etree node from object"""
        return create_node('chunks', None, self.items, {})
    @staticmethod
    def object(node):
        """Create list of `Chunk` objects from etree node"""
        return [Chunk.object(n) for n in node]
Classes
class Chunk (id: str, head: str, phrase: str, attrs: dict)- 
Represents a chunk
Expand source code
@dataclass class Chunk(AttributeGetter): """Represents a chunk""" id: str head: str phrase: str attrs: dict """optional attributes: 'case'""" def __post_init__(self): """Copy compulsory attributes to `attrs` field""" self.attrs.update({'id': self.id, 'head': self.head, 'phrase': self.phrase}) def node(self): """Create etree node from object""" return create_node('chunk', None, [], self.attrs) @staticmethod def object(node): """Create object from etree node""" return Chunk(node.get('id'), node.get('head'), node.get('phrase'), node.attrib)Ancestors
Class variables
var attrs : dict- 
optional attributes: 'case'
 var head : strvar id : strvar phrase : str
Static methods
def object(node)- 
Create object from etree node
Expand source code
@staticmethod def object(node): """Create object from etree node""" return Chunk(node.get('id'), node.get('head'), node.get('phrase'), node.attrib) 
Methods
def node(self)- 
Create etree node from object
Expand source code
def node(self): """Create etree node from object""" return create_node('chunk', None, [], self.attrs) 
Inherited members
 class Chunks (items: List[Chunk])- 
Chunks layer class
Expand source code
@dataclass class Chunks: """Chunks layer class""" items: List[Chunk] def node(self): """Create etree node from object""" return create_node('chunks', None, self.items, {}) @staticmethod def object(node): """Create list of `Chunk` objects from etree node""" return [Chunk.object(n) for n in node]Class variables
var items : List[Chunk]
Static methods
def object(node)- 
Create list of
Chunkobjects from etree nodeExpand source code
@staticmethod def object(node): """Create list of `Chunk` objects from etree node""" return [Chunk.object(n) for n in node] 
Methods
def node(self)- 
Create etree node from object
Expand source code
def node(self): """Create etree node from object""" return create_node('chunks', None, self.items, {})