-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from inception-project/feature/49-Add-argument…
…s-for-score-explanation-etc-to-create_prediction #49 - Add arguments for score, explanation, etc. to create_prediction
- Loading branch information
Showing
13 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install --upgrade -e .[test] | ||
pip install flake8 | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Run tests | ||
run: | | ||
pytest --cov=./ --cov-report=xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
file: ./coverage.xml | ||
env_vars: OS,PYTHON | ||
name: codecov-umbrella |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,53 @@ | ||
from typing import Optional | ||
|
||
from cassis import Cas | ||
from cassis.typesystem import FeatureStructure | ||
|
||
SENTENCE_TYPE = "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence" | ||
TOKEN_TYPE = "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token" | ||
IS_PREDICTION = "inception_internal_predicted" | ||
FEATURE_NAME_SCORE_SUFFIX = "_score" | ||
FEATURE_NAME_SCORE_EXPLANATION_SUFFIX = "_score_explanation" | ||
FEATURE_NAME_AUTO_ACCEPT_MODE_SUFFIX = "_auto_accept" | ||
|
||
|
||
def create_prediction( | ||
cas: Cas, | ||
layer: str, | ||
feature: str, | ||
begin: int, | ||
end: int, | ||
label: str, | ||
score: Optional[int] = None, | ||
score_explanation: Optional[str] = None, | ||
auto_accept: Optional[bool] = None, | ||
) -> FeatureStructure: | ||
""" | ||
Create a prediction | ||
def create_prediction(cas: Cas, layer: str, feature: str, begin: int, end: int, label: str) -> FeatureStructure: | ||
:param cas: the annotated document | ||
:param layer: the layer on which to create the prediction | ||
:param feature: the feature to predict | ||
:param begin: the offset of the first character of the prediction | ||
:param end: the offset of the first character after the prediction | ||
:param label: the predicted label | ||
:param score: the score | ||
:param score_explanation: a rationale for the score / prediction | ||
:param auto_accept: whether the prediction should be automatically accepted | ||
:return: the prediction annotation | ||
""" | ||
AnnotationType = cas.typesystem.get_type(layer) | ||
|
||
fields = {"begin": begin, "end": end, IS_PREDICTION: True, feature: label} | ||
prediction = AnnotationType(**fields) | ||
|
||
if score is not None: | ||
prediction[f"{feature}{FEATURE_NAME_SCORE_SUFFIX}"] = score | ||
|
||
if score_explanation is not None: | ||
prediction[f"{feature}{FEATURE_NAME_SCORE_EXPLANATION_SUFFIX}"] = score_explanation | ||
|
||
if auto_accept is not None: | ||
prediction[f"{feature}{FEATURE_NAME_AUTO_ACCEPT_MODE_SUFFIX}"] = auto_accept | ||
|
||
return prediction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters