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

Commit

Permalink
feat: Dependencies updated README (#59)
Browse files Browse the repository at this point in the history
* corrected pattern name

* updated readme with future work

* updated readme with instructions on how to add further patterns

* expected type correction

* updated test

* refactor: possible fix for mypy error

* refactor: another possible fix for mypy error

Co-authored-by: Aleksandr Sergeev <aleksandr.sergeev@tngtech.com>
Co-authored-by: Lars Reimann <mail@larsreimann.com>
  • Loading branch information
3 people authored Feb 7, 2022
1 parent 135c61e commit e6e9b0e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def package_files(package_name: str) -> list[str]:

def package_root(package_name: str) -> Path:
path_as_string = importlib.import_module(package_name).__file__
if path_as_string is None:
raise AssertionError(f"Cannot find package root for '{path_as_string}'.")
return Path(path_as_string).parent


Expand Down
11 changes: 11 additions & 0 deletions package_parser/package_parser/commands/get_dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ Parsing a dependency subtree in an InOrder traversal, we can rebuild a sentence
### Dependency Tree Example

![Alt text](dependency_tree_example.png "Dependency Tree Example")


## Where to continue work?
* Development of more patterns in _dependency_patterns.py, see [Dependency Parser](https://spacy.io/usage/linguistic-features#dependency-parse), [Dependency Matcher](https://spacy.io/usage/rule-based-matching#dependencymatcher)
* Look into pattern matching over multiple sentences. Have a more theoretical understanding of the meaning of a dependency in the english language.
* Better classification of the subclasses of Actions, Condtions. These classes are found in __../get_api/_model.py__.

### How to continue work?
It is currently constructed such that for each pattern, there exists a corresponding function __extract_(pattern_name)__ within the class DependencyExtractor. This is due to the assumption that different types of dependency patterns will have different structured sentences, and thus require slightly different combinations of methods to extract the wanted information.

The exact naming of the function corresponding to the pattern is required for the pattern ID to name mapping, lines 188-190 in _get_dependency.py.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependency_matcher_patterns = {
"pattern_parameter_subordinating_conjunction": [
"pattern_parameter_adverbial_clause": [
{"RIGHT_ID": "action_head", "RIGHT_ATTRS": {"POS": "VERB"}},
{
"LEFT_ID": "action_head",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from spacy.matcher import DependencyMatcher
from spacy.tokens import Token
from spacy.tokens.doc import Doc
from spacy.tokens.span import Span

from ..get_api._model import (
API,
Expand Down Expand Up @@ -118,7 +119,7 @@ class DependencyExtractor:
"""

@staticmethod
def extract_pattern_parameter_subordinating_conjunction(
def extract_pattern_parameter_adverbial_clause(
dependent_param: Parameter,
func_parameters: List[Parameter],
match: Tuple,
Expand Down Expand Up @@ -153,7 +154,7 @@ def extract_pattern_parameter_subordinating_conjunction(
def extract_dependencies_from_docstring(
parameter: Parameter,
func_parameters: List[Parameter],
param_docstring: str,
param_docstring: Span,
matches: List,
spacy_id_to_pattern_id_mapping: Dict,
) -> List[Dependency]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_extract_condition():
assert condition == Condition(condition="If metric is a string")


def test_extract_dependencies_from_docstring_pattern_subordinating_conjunction():
def test_extract_dependencies_from_docstring_pattern_adverbial_clause():
param_docstring_nlp = nlp("ignored when probability is False")
dependent_param = Parameter(
name="random_state",
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_extract_dependencies_from_docstring_pattern_subordinating_conjunction()
)

extracted_dependency = (
DependencyExtractor.extract_pattern_parameter_subordinating_conjunction(
DependencyExtractor.extract_pattern_parameter_adverbial_clause(
dependent_param=dependent_param,
func_parameters=func_params,
match=match,
Expand Down

0 comments on commit e6e9b0e

Please sign in to comment.