-
Notifications
You must be signed in to change notification settings - Fork 26
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 #425 from abafzal/cat_labels
Categorization projects and manual categorization labels dataset
- Loading branch information
Showing
19 changed files
with
265 additions
and
12 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Categoriation | ||
|
||
* [Project](/beta/categorization/project) |
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,6 @@ | ||
Categorization Project | ||
====================== | ||
|
||
.. autoclass:: tamr_client.CategorizationProject | ||
|
||
.. autofunction:: tamr_client.categorization.project.manual_labels |
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
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,5 @@ | ||
""" | ||
Tamr - Categorization | ||
See https://docs.tamr.com/docs/overall-workflow-classification | ||
""" | ||
from tamr_client.categorization import project |
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,55 @@ | ||
from tamr_client._types import ( | ||
CategorizationProject, | ||
Dataset, | ||
Instance, | ||
JsonDict, | ||
Session, | ||
URL, | ||
) | ||
from tamr_client.dataset import _dataset, unified | ||
|
||
|
||
def _from_json(url: URL, data: JsonDict) -> CategorizationProject: | ||
"""Make Categorization project from JSON data (deserialize) | ||
Args: | ||
url: Project URL | ||
data: Project JSON data from Tamr server | ||
""" | ||
return CategorizationProject( | ||
url, name=data["name"], description=data.get("description") | ||
) | ||
|
||
|
||
def manual_labels( | ||
session: Session, instance: Instance, project: CategorizationProject | ||
) -> Dataset: | ||
"""Get manual labels from a Categorization project | ||
Args: | ||
instance: Tamr instance containing project | ||
project: Tamr project containing labels | ||
Returns: | ||
Dataset containing manual labels | ||
Raises: | ||
_dataset.NotFound: If no dataset could be found at the specified URL | ||
Ambiguous: If multiple targets match dataset name | ||
""" | ||
unified_dataset = unified.from_project( | ||
session=session, instance=instance, project=project | ||
) | ||
labels_dataset_name = unified_dataset.name + "_manual_categorizations" | ||
datasets_url = URL(instance=instance, path="datasets") | ||
r = session.get( | ||
url=str(datasets_url), params={"filter": f"name=={labels_dataset_name}"} | ||
) | ||
matches = r.json() | ||
if len(matches) == 0: | ||
raise _dataset.NotFound(str(r.url)) | ||
if len(matches) > 1: | ||
raise _dataset.Ambiguous(str(r.url)) | ||
|
||
dataset_path = matches[0]["relativeId"] | ||
dataset_url = URL(instance=instance, path=dataset_path) | ||
return _dataset._from_url(session=session, url=dataset_url) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import tamr_client as tc | ||
from tests.tamr_client import fake | ||
|
||
|
||
@fake.json | ||
def test_manual_labels(): | ||
s = fake.session() | ||
instance = fake.instance() | ||
project = fake.categorization_project() | ||
|
||
tc.categorization.project.manual_labels( | ||
session=s, instance=instance, project=project | ||
) |
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
99 changes: 99 additions & 0 deletions
99
tests/tamr_client/fake_json/categorization/test_project/test_manual_labels.json
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,99 @@ | ||
[ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"path": "projects/2/unifiedDataset" | ||
}, | ||
"response": { | ||
"json": { | ||
"id": "unify://unified-data/v1/datasets/161", | ||
"name": "Party_Categorization_Unified_Dataset", | ||
"description": "", | ||
"version": "3607", | ||
"keyAttributeNames": [ | ||
"tamr_id" | ||
], | ||
"tags": [], | ||
"created": { | ||
"username": "afsana.afzal", | ||
"time": "2020-05-21T15:18:38.575Z", | ||
"version": "18336" | ||
}, | ||
"lastModified": { | ||
"username": "workflow.bot", | ||
"time": "2020-06-18T15:18:30.833Z", | ||
"version": "149940" | ||
}, | ||
"relativeId": "datasets/161", | ||
"upstreamDatasetIds": [ | ||
"unify://unified-data/v1/datasets/106" | ||
], | ||
"externalId": "Party_Categorization_Unified_Dataset" | ||
} | ||
} | ||
}, | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"path": "datasets?filter=name==Party_Categorization_Unified_Dataset_manual_categorizations" | ||
}, | ||
"response": { | ||
"json": [ | ||
{ | ||
"id": "unify://unified-data/v1/datasets/167", | ||
"name": "Party_Categorization_Unified_Dataset_manual_categorizations", | ||
"description": "Manual categorizations", | ||
"version": "2992", | ||
"keyAttributeNames": [ | ||
"recordId" | ||
], | ||
"tags": [], | ||
"created": { | ||
"username": "afsana.afzal", | ||
"time": "2020-06-01T20:49:46.549Z", | ||
"version": "57920" | ||
}, | ||
"lastModified": { | ||
"username": "workflow.bot", | ||
"time": "2020-06-18T15:32:44.631Z", | ||
"version": "150069" | ||
}, | ||
"relativeId": "datasets/167", | ||
"upstreamDatasetIds": [], | ||
"externalId": "Party_Categorization_Unified_Dataset_manual_categorizations" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"path": "datasets/167" | ||
}, | ||
"response": { | ||
"json": { | ||
"id": "unify://unified-data/v1/datasets/167", | ||
"name": "Party_Categorization_Unified_Dataset_manual_categorizations", | ||
"description": "Manual categorizations", | ||
"version": "2992", | ||
"keyAttributeNames": [ | ||
"recordId" | ||
], | ||
"tags": [], | ||
"created": { | ||
"username": "afsana.afzal", | ||
"time": "2020-06-01T20:49:46.549Z", | ||
"version": "57920" | ||
}, | ||
"lastModified": { | ||
"username": "workflow.bot", | ||
"time": "2020-06-18T15:32:44.631Z", | ||
"version": "150069" | ||
}, | ||
"relativeId": "datasets/167", | ||
"upstreamDatasetIds": [], | ||
"externalId": "Party_Categorization_Unified_Dataset_manual_categorizations" | ||
} | ||
} | ||
} | ||
] |
29 changes: 29 additions & 0 deletions
29
tests/tamr_client/fake_json/test_project/test_from_resource_id_categorization.json
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,29 @@ | ||
[ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"path": "projects/2" | ||
}, | ||
"response": { | ||
"json": { | ||
"id": "unify://unified-data/v1/projects/2", | ||
"name": "Party Categorization", | ||
"description": "Categorizes organization at the Party/Domestic level", | ||
"type": "CATEGORIZATION", | ||
"unifiedDatasetName": "party_categorization_unified_dataset", | ||
"created": { | ||
"username": "admin", | ||
"time": "2020-08-04T14:54:11.767Z", | ||
"version": "20" | ||
}, | ||
"lastModified": { | ||
"username": "admin", | ||
"time": "2020-08-04T14:54:11.767Z", | ||
"version": "21" | ||
}, | ||
"relativeId": "projects/2", | ||
"externalId": "98f9e4ee-1a35-4242-917d-1163363d5411" | ||
} | ||
} | ||
} | ||
] |
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