Esempio n. 1
0
 def test_add_child(self):
     child0 = Node("child0")
     child1 = Node("child1")
     node = Node("label")
     node.add_child(child0)
     node.add_child(child1)
     self.assertEqual(node.children[0], child0)
     self.assertEqual(node.children[1], child1)
Esempio n. 2
0
 def hint(self, node: Node, expected):
     """
     Method used recursively to add hints and expectations to nodes in the node structure
     :param node: The node for which the hints and expectations should be added
     :param expected: The expected nodes at the current level
     """
     if expected:
         found = [child.category for child in node]
         if isinstance(expected.get(node.category), list):
             for category in expected[node.category]:
                 if category not in found:
                     if category in self.labels:
                         leaf = LabelNode(category, self.labels[category])
                     else:
                         leaf = Node(category)
                     node.add_child(leaf)
     for child in node:
         if child.category in self.hints:
             child.hint = self.hints[child.category]
         if expected:
             next_level = expected.get(node.category)
             if isinstance(next_level, dict):
                 self.hint(child, next_level)
Esempio n. 3
0
def parse(text: str) -> Node:
    """
    Method used to process hersen text
    :param text: Text that needs processing
    :return: For now a stub reportnode, as hinternlp is not implemented
    """

    text = "ongeveer 2, 3 cm zichtbaar ependymomas"
    root = Node("report", (text, 96))
    pos1 = Node("positive finding", (text, 96))
    mass1 = Node("mass", (text, 96))
    size1 = Node("size", ("ongeveer 2, 3 cm", 40), hint="The size of the mass")
    multifocality1 = Node("Multifocality", ("zichtbaar ependymomas", 80))
    hin = ("Multiple tumors in the brain usually indicate metastatic disease (figure)."
           "Primary brain tumors are typically seen in a single region, but some brain tumors like lymphomas, "
           "multicentric glioblastomas and gliomatosis cerebri can be multifocal. Some tumors can be multifocal"
           " as a result of seeding metastases: this can occur in medulloblastomas (PNET-MB), ependymomas, GBMs "
           "and oligodendrogliomas. Meningiomas and schwannomas can be multiple, especially in neurofibromatosis"
           " type II")
    types = ["meningiomas", "ependymomas", "choroid plexus papillomas"]
    mass1.add_child(size1)
    neur = LabelNode("Neurofibromatosis II", types, ("zichtbaar ependymomas", 80), ("ependymomas", 80), hint=hin)
    multifocality1.add_child(neur)
    mass1.add_child(multifocality1)

    # speculative child
    location = Node("location")
    mass1.add_child(location)

    pos1.add_child(mass1)
    root.add_child(pos1)

    return root