Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Esukhia/antx
Browse files Browse the repository at this point in the history
  • Loading branch information
10zinten committed May 3, 2021
2 parents a0e4f3a + 6cfeaa8 commit 44e4c76
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ jobs:
- name: Python Semantic Release
uses: relekang/python-semantic-release@master
with:
github_token: ${{ secrets.GH_TOKEN }}
pypi_token: ${{ secrets.PYPI_PASSWORD }}
github_token: ${{ secrets.GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog

<!--next-version-placeholder-->

## v0.1.8 (2021-05-03)
### Fix
* **version:** Version increased ([`d8436df`](https://github.com/Esukhia/antx/commit/d8436dfd424710a73cee4b9f4c0c61707e589d03))

## v0.1.7 (2021-05-03)
### Fix
* **core:** Freezed diff compute feature rollback ([`9ec6ab5`](https://github.com/Esukhia/antx/commit/9ec6ab53a01c307bdf753911f525dc7b86dbaad0))

## v0.1.6 (2021-05-03)
### Fix
* Publish ([`3a20a81`](https://github.com/Esukhia/antx/commit/3a20a810312361f5fcbcc571551679d6baee08be))
* Install ([`d6d86e1`](https://github.com/Esukhia/antx/commit/d6d86e18aced5bee358996af1e0c79f075c4d438))
* Install ([`8c31dd3`](https://github.com/Esukhia/antx/commit/8c31dd3f484bec8254e3280ef3e40dc3733a1450))
* Install ([`e5f1c91`](https://github.com/Esukhia/antx/commit/e5f1c910bebbbd32e095b2820777eb8c99606d5a))
* Deps version ([`4838692`](https://github.com/Esukhia/antx/commit/48386920211fd9d24f6e348c427c4f215330bfe2))
* Specify lower & upper bound for deps ([`50705dc`](https://github.com/Esukhia/antx/commit/50705dcca6caedc8b8b82ddadb7c9c9f300d77fd))
* **setup:** Import pathlib and re ([`eca80f7`](https://github.com/Esukhia/antx/commit/eca80f7375ac7543fae4abe2127eddd4c8715b30))
* **github-action:** Rewuirement file name changed ([`95a4dec`](https://github.com/Esukhia/antx/commit/95a4dece87d957914b84094fceb40811c24a3cd5))
* **github-action:** Automated publish on pip ([`0720654`](https://github.com/Esukhia/antx/commit/07206548bf933e45c27a1fe866a08589c72e4eaa))
* **core:** Freeze computation implemented ([`72c894a`](https://github.com/Esukhia/antx/commit/72c894a4405ece635dcc55b09138532e6808dae9))
* **core:** Implemented memoization for get_diffs ([`0756879`](https://github.com/Esukhia/antx/commit/07568795d6c60416d3058c5e2f2ce8f641ff6472))
2 changes: 1 addition & 1 deletion antx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .core import transfer

# Version of the annotation transfer package
__version__ = "0.1.5"
__version__ = "0.1.8"
1 change: 0 additions & 1 deletion antx/config.py

This file was deleted.

28 changes: 3 additions & 25 deletions antx/core.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import ast
import re
import pickle
from pathlib import Path
import hashlib

import yaml

from .utils import optimized_diff_match_patch
from .config import *

tofu_lower_limit = 200000
tofu_upper_limit = 1112064
Expand Down Expand Up @@ -138,7 +133,7 @@ def filter_diff(diffs_list, tofu_mapping):
return result


def transfer(source, patterns, target, output="txt", replaced=True):
def transfer(source, patterns, target, output="txt"):
"""Extract annotations from with regex patterns and transfer to target.
Arguments:
Expand All @@ -155,25 +150,8 @@ def transfer(source, patterns, target, output="txt", replaced=True):
Can also return the diff in yaml or a string containing target+annotations
"""
print(f"Annotation transfer started...")
result = ''
tofu_source, tofu_mapping = tag_to_tofu(source, patterns)
md5 = hashlib.md5(str.encode(source + target + str(patterns)))
hash_value = md5.hexdigest()
cache_diff_path = Path(CACHE_DIR) / str(hash_value)
if not replaced:
if cache_diff_path.is_file():
diffs = pickle.loads(cache_diff_path.read_bytes())
else:
diffs = get_diffs(tofu_source, target)
pickle_diffs = pickle.dumps(list(diffs))
cache_diff_path.write_bytes(pickle_diffs)
else:
cache_files = list(Path(CACHE_DIR).iterdir())
for cache_file in cache_files:
cache_file.unlink()
diffs = list(get_diffs(tofu_source, target))
pickle_diffs = pickle.dumps(diffs)
cache_diff_path.write_bytes(pickle_diffs)
diffs = get_diffs(tofu_source, target)

filterred_diff = filter_diff(diffs, tofu_mapping)

Expand All @@ -183,4 +161,4 @@ def transfer(source, patterns, target, output="txt", replaced=True):
result = to_yaml(filterred_diff)
elif output == "txt":
result = to_text(filterred_diff)
return result
return result
8 changes: 0 additions & 8 deletions tests/test_annotation_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ def test_ann_transfer_optimized(
assert annotated == expected


def test_ann_transfer_using_cache(
source_text, target_text, annotation_patterns, expected
):
annotated = transfer(
source_text, annotation_patterns, target_text, "txt", replaced=False
)
assert annotated == expected

def test_transfer_hfml_tags():
layer_1 = "<񉏠k1ཀཀཀཀ>\n ཁཁཁཁ"
layer_2 = "ཀཀཀཀ\n <񉏠auཁཁཁཁ>"
Expand Down

0 comments on commit 44e4c76

Please sign in to comment.