def setup(self): self.annotation_graph = poioapi.annotationgraph.AnnotationGraph( data.DataStructureTypeGraid()) filename = os.path.join(os.path.dirname(__file__), "sample_files", "balochi_graf", "balochi.hdr") self.annotation_graph.from_graf(filename) self.data_structure_type = data.DataStructureTypeGraid() self.anngraphfilter = poioapi.annotationgraph.AnnotationGraphFilter( self.annotation_graph)
def setup(self): # Initialize the DataStructureType class self.data_structure_type = data.DataStructureTypeGraid() # Initialize the AnnotationTree class self.annotationtree = annotationtree.AnnotationTree( self.data_structure_type)
def test_element_passes_filter(self): """Raise an assertion if can't pass the filter. Verify if a specific element passes in through a filter. Raises ------ AssertionError If the results there aren't the expected. """ # Open the file and set it to the AnnotationTree data_structure_type = data.DataStructureTypeGraid() anntreefilter = annotationtree.AnnotationTreeFilter( data_structure_type) anntreefilter.set_filter_for_type("graid2", "nc") # If the variables value equal like this element = [{ 'id': 6, 'annotation': 'gu\u0161-\u012bt:' }, [[{ 'id': 4, 'annotation': 'gu\u0161-\u012bt:' }, [[{ 'id': 1, 'annotation': 'gu\u0161-\u012bt:' }, { 'id': 2, 'annotation': 'say.PRS-3SG' }, { 'id': 3, 'annotation': '' }]], { 'id': 5, 'annotation': 'nc' }]], { 'id': 7, 'annotation': 'They say:' }, { 'id': 8, 'annotation': '' }] # The result expected should be expected_result = True # Boolean value assert ( anntreefilter.element_passes_filter(element) == expected_result)
def load_tree_from_pickle(self, filepath): """Load the project annotation tree from a pickle file. Parameters ---------- filepath : str The absolute path to a file. """ file = open(filepath, 'rb') loaded_data = pickle.load(file) if loaded_data[0] == 'poio_pickle_v2': self.reset_data_structure_type( data.data_structure_handler_for_type(loaded_data[1])) self.tree = loaded_data[2] else: file.seek(0) self.reset_data_structure_type(data.DataStructureTypeGraid()) self.tree = pickle.load(file) file.close()
def test_get_children_of_type(self): """Assert that `get_children_of_type()` works fine. `get_children_of_type()` returns all the elements that are beneath a given type in the type hierarchy. Raises ------ AssertionError If the results there aren't the expected. """ ann_type = 'utterance' expected_result = ['word', 'translation'] assert (self.data_structure_type.get_children_of_type( ann_type) == expected_result) data_structure_type = data.DataStructureTypeGraid() ann_type = 'utterance' expected_result = ['clause_unit', 'graid2', 'translation', 'comment'] assert (data_structure_type.get_children_of_type( ann_type) == expected_result)
from poioapi import annotationtree from poioapi import data # Initialize the variable annotation_tree = annotationtree.AnnotationTree(data.GLOSS) # Open the file and set it to the AnnotationTree filepath = 'Balochi Text1.pickle' file = open(filepath, "rb") annotation_tree.tree = pickle.load(file) # Initialize the list that will contain the result values filterChain = [] # Choose the data structure type data_structure_type = data.DataStructureTypeGraid() # Initialize the corpus to the file reader corpus = corpus.CorpusTrees(data_structure_type) corpus.add_item(filepath, data.TREEPICKLE) # Set the filter structure currentFilter = annotationtree.AnnotationTreeFilter(data_structure_type) # Most important part set the filter with the defined words to search in each part of the data structure # for ann_type in data_structure_type.flat_data_hierarchy: # # Find a way to set the text here # currentFilter.set_filter_for_type(ann_type, unicode(value)) # But for let's use a directly approach # This two variables representes a field of structure and it's value
def setup(self): self.data_structure_type = data.DataStructureType() self.data_structure_type_graid = data.DataStructureTypeGraid()