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

fix: display of math blocks #421

Merged
merged 6 commits into from
Feb 17, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ const DocumentationText: React.FC<DocumentationTextProps> = function ({
inputText = '',
}) {
const preprocessedText = inputText
// replace single new-lines by spaces
.replaceAll(/(?<!\n)\n(?!\n)/gu, ' ')
// replace inline math elements
.replaceAll(/:math:`([^`]*)`/gu, '$$1$')
// replace block math elements
.replaceAll(/\.\. math::\s*(\S.*)\n\n/gu, '$$\n$1\n$$\n\n');

const shortenedText = preprocessedText.split('\n\n')[0];
Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-parser/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# library-analyzer
# package-parser

A tool to analyzer client and API code written in Python.
A tool to analyze client and API code written in Python.

## Usage

Expand Down
8 changes: 8 additions & 0 deletions package-parser/package_parser/commands/get_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from ._get_api import get_api
from ._model import (
API,
Action,
APIDependencies,
Class,
Condition,
Dependency,
FromImport,
Function,
Import,
Module,
Parameter,
ParameterAndResultDocstring,
ParameterAssignment,
ParameterHasValue,
ParameterIsIgnored,
ParameterIsIllegal,
ParameterIsNone,
Result,
)
from ._package_metadata import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ def __description(numpydoc: NumpyDocString) -> str:

result = ""
if has_summary:
result += " ".join(numpydoc["Summary"])
result += "\n".join(numpydoc["Summary"])
if has_summary and has_extended_summary:
result += "\n\n"
if has_extended_summary:
result += " ".join(numpydoc["Extended Summary"])
result += "\n".join(numpydoc["Extended Summary"])
return result

@staticmethod
Expand Down
80 changes: 33 additions & 47 deletions package-parser/package_parser/commands/get_api/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,29 @@ def to_json(self) -> Any:
}


@dataclass
class Import:
module_name: str
alias: Optional[str]

@staticmethod
def from_json(json: Any) -> Import:
return Import(json["module"], json["alias"])

def __init__(self, module_name: str, alias: Optional[str]):
self.module: str = module_name
self.alias: Optional[str] = alias

def to_json(self) -> Any:
return {"module": self.module, "alias": self.alias}
return {"module": self.module_name, "alias": self.alias}


@dataclass
class FromImport:
module_name: str
declaration_name: str
alias: Optional[str]

@staticmethod
def from_json(json: Any) -> FromImport:
return FromImport(json["module"], json["declaration"], json["alias"])

def __init__(self, module_name: str, declaration_name: str, alias: Optional[str]):
self.module_name: str = module_name
self.declaration_name: str = declaration_name
self.alias: Optional[str] = alias

def to_json(self) -> Any:
return {
"module": self.module_name,
Expand Down Expand Up @@ -256,7 +256,17 @@ def to_json(self) -> Any:
}


@dataclass
class Function:
qname: str
decorators: list[str]
parameters: list[Parameter]
results: list[Result]
is_public: bool
description: str
docstring: str
source_code: str

@staticmethod
def from_json(json: Any) -> Function:
return Function(
Expand All @@ -273,26 +283,6 @@ def from_json(json: Any) -> Function:
json["source_code"],
)

def __init__(
self,
qname: str,
decorators: list[str],
parameters: list[Parameter],
results: list[Result],
is_public: bool,
description: str,
docstring: str,
source_code: str,
) -> None:
self.qname: str = qname
self.decorators: list[str] = decorators
self.parameters: list[Parameter] = parameters
self.results: list[Result] = results
self.is_public: bool = is_public
self.description: str = description
self.docstring: str = inspect.cleandoc(docstring or "")
self.source_code: str = source_code

@property
def name(self) -> str:
return self.qname.split(".")[-1]
Expand Down Expand Up @@ -370,7 +360,7 @@ def from_docstring(cls, docstring: ParameterAndResultDocstring) -> RefinedType:

def __init__(
self,
ref_type: Optional[Union[UnionType, BoundaryType, EnumType, NamedType]] = None,
ref_type: Union[UnionType, BoundaryType, EnumType, NamedType, None] = None,
) -> None:
self.ref_type = ref_type

Expand Down Expand Up @@ -423,34 +413,30 @@ class ParameterAssignment(Enum):
NAME_ONLY = (auto(),)


@dataclass
class Result:
name: str
docstring: ParameterAndResultDocstring

@staticmethod
def from_json(json: Any) -> Result:
return Result(
json["name"], ParameterAndResultDocstring.from_json(json["docstring"])
)

def __init__(self, name: str, docstring: ParameterAndResultDocstring) -> None:
self.name: str = name
self.docstring = docstring

def to_json(self) -> Any:
return {"name": self.name, "docstring": self.docstring.to_json()}


@dataclass
class ParameterAndResultDocstring:
type: str
description: str

@classmethod
def from_json(cls, json: Any):
return cls(json["type"], json["description"])

def __init__(
self,
type_: str,
description: str,
) -> None:
self.type: str = type_
self.description: str = description

def to_json(self) -> Any:
return {"type": self.type, "description": self.description}

Expand Down Expand Up @@ -529,10 +515,10 @@ class Dependency:
@classmethod
def from_json(cls, json: Any):
return cls(
Parameter.from_json(["hasDependentParameter"]),
Parameter.from_json(["isDependingOn"]),
Condition.from_json(["hasCondition"]),
Action.from_json(["hasAction"]),
Parameter.from_json(json["hasDependentParameter"]),
Parameter.from_json(json["isDependingOn"]),
Condition.from_json(json["hasCondition"]),
Action.from_json(json["hasAction"]),
)

def to_json(self) -> Dict:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dependency Extaction
# Dependency Extraction

## How do we imagine a Dependency

Expand All @@ -16,13 +16,13 @@ Parsing a dependency subtree in an InOrder traversal, we can rebuild a sentence

### Dependency Tree Example

![Alt text](../../../package_parser/commands/get_dependencies/dependency_tree_example.png "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__.
* Better classification of the subclasses of Actions, Conditions. 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from spacy.tokens.doc import Doc
from spacy.tokens.span import Span

from ..get_api._model import (
from ..get_api import (
API,
Action,
APIDependencies,
Expand Down Expand Up @@ -61,7 +61,7 @@ def extract_action(action_token: Token, condition_token: Token) -> Action:
if token != condition_token:
action_tokens.extend(extract_lefts_and_rights(token))

# Remove trailing punctiation
# Remove trailing punctuation
if any(p == action_tokens[-1] for p in [",", "."]):
del action_tokens[-1]
action_text = " ".join(action_tokens)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Dependency,
Parameter,
ParameterAndResultDocstring,
ParameterAssignment,
ParameterHasValue,
ParameterIsIgnored,
ParameterIsIllegal,
Expand Down Expand Up @@ -99,18 +100,18 @@ def test_extract_dependencies_from_docstring_pattern_adverbial_clause():
name="random_state",
default_value=None,
is_public=True,
assigned_by="NAME_ONLY",
assigned_by=ParameterAssignment.NAME_ONLY,
docstring=ParameterAndResultDocstring(
type_="param possible types", description=param_docstring_nlp.text
type="param possible types", description=param_docstring_nlp.text
),
)
dependee_param = Parameter(
name="probability",
default_value=None,
is_public=True,
assigned_by="NAME_ONLY",
assigned_by=ParameterAssignment.NAME_ONLY,
docstring=ParameterAndResultDocstring(
type_="param possible types", description="param probability docstring"
type="param possible types", description="param probability docstring"
),
)
pattern_parameter_subordinating_conjunction = nlp(
Expand Down