Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Fix/parse tree bug #29

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions blabla/sentence_processor/sentence_processing_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from blabla.sentence_processor.yngve_tree import YngveNode
from blabla.sentence_processor.pos_tag_counting_engine import PosTagCounter
from blabla.utils.exceptions import *
from blabla.utils.utils import get_nltk_tree
import blabla.utils.settings as settings
from blabla.utils.global_params import *
import os
Expand Down Expand Up @@ -140,9 +141,8 @@ def const_parse_tree(self):
parseTree (CoreNLP): The CoreNLP constituency parse tree object
"""
document = self.client.annotate(self._sent)
document = json.loads(document.text)
pt = document["sentences"][0]["parse"]
parseTree = Tree.fromstring(pt)
parseTree = document.sentence[0].parseTree
parseTree = get_nltk_tree(parseTree)
return parseTree

def num_words(self):
Expand Down
18 changes: 18 additions & 0 deletions blabla/utils/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""A file containing helper functions"""

from nltk.tree import Tree
from typing import Any


def get_nltk_tree(parse_tree: Any) -> Tree:
"""Given a parse_tree obtained from CoreNLP, this function recursively generates an NLTK
Tree based on the parse_tree information.
Args:
parse_tree (CoreNLP_pb2.ParseTree): The CoreNLP formatted parse tree
Returns:
(Tree): The parse tree converted into NLTK format
"""
return Tree(
parse_tree.value,
[get_nltk_tree(child) for child in parse_tree.child]
) if parse_tree.child else parse_tree.value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF \n

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
],
download_url="https://github.com/novoic/blabla/archive/v0.2.2.tar.gz",
install_requires=[
"stanza==1.0.0",
"stanza>=1.0.0,<2.0.0",
"flask==1.1.2",
"jsonpickle==1.4",
"anytree==2.8.0",
Expand Down