mmif-python 0.0.1__tar.gz → 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- usr/lib/python3.8/site-packages/mmif/__init__.py +18 -0
- usr/lib/python3.8/site-packages/mmif/__pycache__/__init__.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/res/__init__.py +0 -0
- usr/lib/python3.8/site-packages/mmif/res/__pycache__/__init__.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/serialize/__init__.py +6 -0
- usr/lib/python3.8/site-packages/mmif/serialize/__pycache__/__init__.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/serialize/__pycache__/annotation.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/serialize/__pycache__/medium.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/serialize/__pycache__/mmif.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/serialize/__pycache__/model.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/serialize/__pycache__/view.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/serialize/annotation.py +34 -0
- usr/lib/python3.8/site-packages/mmif/serialize/medium.py +52 -0
- usr/lib/python3.8/site-packages/mmif/serialize/mmif.py +89 -0
- usr/lib/python3.8/site-packages/mmif/serialize/model.py +112 -0
- usr/lib/python3.8/site-packages/mmif/serialize/view.py +72 -0
- usr/lib/python3.8/site-packages/mmif/ver/__init__.py +1 -0
- usr/lib/python3.8/site-packages/mmif/ver/__pycache__/__init__.cpython-38.pyc +0 -0
- usr/lib/python3.8/site-packages/mmif/vocab/__pycache__/__init__.cpython-38.pyc +0 -0
- {mmif-python-0.0.1 → usr/lib/python3.8/site-packages/mmif_python-0.1.0-py3.8.egg-info}/PKG-INFO +3 -2
- usr/lib/python3.8/site-packages/mmif_python-0.1.0-py3.8.egg-info/SOURCES.txt +20 -0
- usr/lib/python3.8/site-packages/mmif_python-0.1.0-py3.8.egg-info/requires.txt +13 -0
- mmif-python-0.0.1/README.md +0 -17
- mmif-python-0.0.1/mmif/__init__.py +0 -2
- mmif-python-0.0.1/mmif/serialize/__init__.py +0 -173
- mmif-python-0.0.1/mmif_python.egg-info/PKG-INFO +0 -33
- mmif-python-0.0.1/mmif_python.egg-info/SOURCES.txt +0 -9
- mmif-python-0.0.1/setup.cfg +0 -4
- mmif-python-0.0.1/setup.py +0 -23
- {mmif-python-0.0.1 → usr/lib/python3.8/site-packages}/mmif/vocab/__init__.py +0 -0
- {mmif-python-0.0.1/mmif_python.egg-info → usr/lib/python3.8/site-packages/mmif_python-0.1.0-py3.8.egg-info}/dependency_links.txt +0 -0
- {mmif-python-0.0.1/mmif_python.egg-info → usr/lib/python3.8/site-packages/mmif_python-0.1.0-py3.8.egg-info}/top_level.txt +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
_res_pkg = 'res'
|
|
2
|
+
_ver_pkg = 'ver'
|
|
3
|
+
__version__ = 'UNK'
|
|
4
|
+
_schema_res_oriname = 'schema/mmif.json'
|
|
5
|
+
_schema_res_name = 'mmif.json'
|
|
6
|
+
_vocab_res_oriname = 'vocabulary/clams.vocabulary.yaml'
|
|
7
|
+
_vocab_res_name = 'clams.vocabulary.yaml'
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
import importlib
|
|
11
|
+
i = importlib.import_module(f'{__name__}.{_ver_pkg}')
|
|
12
|
+
__version__ = i.__version__ # pytype: disable=attribute-error
|
|
13
|
+
except ImportError:
|
|
14
|
+
# don't set version
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
from mmif.serialize import *
|
|
18
|
+
from mmif.vocab import *
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from typing import Dict, Union, Optional
|
|
2
|
+
|
|
3
|
+
from .model import MmifObject
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Annotation(MmifObject):
|
|
7
|
+
properties: 'AnnotationProperties'
|
|
8
|
+
_type: str
|
|
9
|
+
|
|
10
|
+
@property
|
|
11
|
+
def id(self):
|
|
12
|
+
return self.properties.id
|
|
13
|
+
|
|
14
|
+
@id.setter
|
|
15
|
+
def id(self, aid):
|
|
16
|
+
self.properties.id = aid
|
|
17
|
+
|
|
18
|
+
def _deserialize(self, input_dict: dict) -> None:
|
|
19
|
+
self._type = input_dict['_type']
|
|
20
|
+
self.properties = AnnotationProperties(input_dict['properties'])
|
|
21
|
+
|
|
22
|
+
def __init__(self, anno_obj: Union[str, dict] = None):
|
|
23
|
+
self._type = ''
|
|
24
|
+
self.properties = AnnotationProperties()
|
|
25
|
+
super().__init__(anno_obj)
|
|
26
|
+
|
|
27
|
+
def add_property(self, name: str, value: str):
|
|
28
|
+
self.properties[name] = value
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AnnotationProperties(MmifObject):
|
|
32
|
+
id: str
|
|
33
|
+
start: Optional[int] = -1
|
|
34
|
+
end: Optional[int] = -1
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from typing import Union, Optional, List
|
|
2
|
+
|
|
3
|
+
from .model import MmifObject
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Medium(MmifObject):
|
|
7
|
+
id: str
|
|
8
|
+
type: str
|
|
9
|
+
mime: Optional[str] = None
|
|
10
|
+
location: Optional[str] = None
|
|
11
|
+
text: Optional['Text'] = None
|
|
12
|
+
metadata: Optional['MediumMetadata'] = None
|
|
13
|
+
submedia: Optional[List['Submedia']] = None
|
|
14
|
+
|
|
15
|
+
def __init__(self, medium_obj: Union[str, dict] = None):
|
|
16
|
+
self.id = ''
|
|
17
|
+
self.type = ''
|
|
18
|
+
super().__init__(medium_obj)
|
|
19
|
+
|
|
20
|
+
def _deserialize(self, medium_dict: dict):
|
|
21
|
+
self.id = medium_dict['id']
|
|
22
|
+
self.type = medium_dict['type']
|
|
23
|
+
if 'metadata' in medium_dict:
|
|
24
|
+
self.metadata = MediumMetadata(medium_dict.get('metadata'))
|
|
25
|
+
if 'mime' in medium_dict:
|
|
26
|
+
self.mime = medium_dict['mime']
|
|
27
|
+
if 'location' in medium_dict:
|
|
28
|
+
self.location = medium_dict['location']
|
|
29
|
+
if 'text' in medium_dict:
|
|
30
|
+
self.text = Text(medium_dict['text'])
|
|
31
|
+
|
|
32
|
+
def add_metadata(self, name: str, value: str):
|
|
33
|
+
self.metadata[name] = value
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Text(MmifObject):
|
|
37
|
+
_value: str
|
|
38
|
+
_language: Optional[str]
|
|
39
|
+
|
|
40
|
+
def __init__(self, text_obj: Union[str, dict]):
|
|
41
|
+
super().__init__(text_obj)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class MediumMetadata(MmifObject):
|
|
45
|
+
source: str
|
|
46
|
+
tool: str
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Submedia(MmifObject):
|
|
50
|
+
id: str
|
|
51
|
+
annotation: str
|
|
52
|
+
text: 'Text'
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Dict, List, Union
|
|
3
|
+
|
|
4
|
+
from jsonschema import validate
|
|
5
|
+
from pkg_resources import resource_stream
|
|
6
|
+
|
|
7
|
+
import mmif
|
|
8
|
+
from .view import View
|
|
9
|
+
from .medium import Medium
|
|
10
|
+
from .model import MmifObject
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Mmif(MmifObject):
|
|
14
|
+
# TODO (krim @ 7/6/20): maybe need IRI/URI as a python class for typing?
|
|
15
|
+
_context: str
|
|
16
|
+
metadata: Dict[str, str]
|
|
17
|
+
media: List['Medium']
|
|
18
|
+
views: List['View']
|
|
19
|
+
|
|
20
|
+
def __init__(self, mmif_obj: Union[str, dict] = None, validate: bool = True):
|
|
21
|
+
self._context = ''
|
|
22
|
+
self.metadata = {}
|
|
23
|
+
self.media = []
|
|
24
|
+
self.views = []
|
|
25
|
+
if validate:
|
|
26
|
+
self.validate(mmif_obj)
|
|
27
|
+
super().__init__(mmif_obj)
|
|
28
|
+
|
|
29
|
+
def _deserialize(self, input_dict: dict) -> None:
|
|
30
|
+
self._context = input_dict['_context']
|
|
31
|
+
self.metadata = input_dict['metadata']
|
|
32
|
+
self.media = [Medium(m) for m in input_dict['media']]
|
|
33
|
+
self.views = [View(v) for v in input_dict['views']]
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def validate(json_str: Union[str, dict]):
|
|
37
|
+
# NOTE that schema file first needs to be copied to resources directory
|
|
38
|
+
# this is automatically done via setup.py, so for users this shouldn't be a matter
|
|
39
|
+
|
|
40
|
+
schema_res = resource_stream(f'{mmif.__name__}.{mmif._res_pkg}', mmif._schema_res_name)
|
|
41
|
+
schema = json.load(schema_res)
|
|
42
|
+
schema_res.close()
|
|
43
|
+
if type(json_str) == str:
|
|
44
|
+
json_str = json.loads(json_str)
|
|
45
|
+
validate(json_str, schema)
|
|
46
|
+
|
|
47
|
+
def new_view_id(self):
|
|
48
|
+
return 'v_' + str(len(self.views))
|
|
49
|
+
|
|
50
|
+
def new_view(self):
|
|
51
|
+
new_view = View()
|
|
52
|
+
new_view.id = self.new_view_id()
|
|
53
|
+
self.views.append(new_view)
|
|
54
|
+
return new_view
|
|
55
|
+
|
|
56
|
+
def add_media(self, medium: Medium):
|
|
57
|
+
try:
|
|
58
|
+
self.get_medium_location(medium.type)
|
|
59
|
+
# TODO (krim @ 10/7/2018): if get_m_location returns, raise "already exists" error
|
|
60
|
+
except Exception:
|
|
61
|
+
self.media.append(medium)
|
|
62
|
+
|
|
63
|
+
def get_medium_location(self, md_type: str) -> str:
|
|
64
|
+
for medium in self.media:
|
|
65
|
+
if medium["type"] == md_type:
|
|
66
|
+
return medium["location"]
|
|
67
|
+
raise Exception("{} type media not found".format(md_type))
|
|
68
|
+
|
|
69
|
+
def get_medium_by_id(self, id: str) -> 'Medium':
|
|
70
|
+
for medium in self.media:
|
|
71
|
+
if medium.id == id:
|
|
72
|
+
return medium
|
|
73
|
+
raise Exception("{} medium not found".format(id))
|
|
74
|
+
|
|
75
|
+
def get_view_by_id(self, id: str) -> 'View':
|
|
76
|
+
for view in self.views:
|
|
77
|
+
if view.id == id:
|
|
78
|
+
return view
|
|
79
|
+
raise Exception("{} view not found".format(id))
|
|
80
|
+
|
|
81
|
+
def get_all_views_contain(self, at_type: str):
|
|
82
|
+
return [view for view in self.views if at_type in view.metadata.contains]
|
|
83
|
+
|
|
84
|
+
def get_view_contains(self, at_type: str):
|
|
85
|
+
# will return the *latest* view
|
|
86
|
+
for view in reversed(self.views):
|
|
87
|
+
if at_type in view.metadata.contains:
|
|
88
|
+
return view
|
|
89
|
+
return None
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Union, Any, Dict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MmifObject(object):
|
|
6
|
+
"""
|
|
7
|
+
Abstract superclass for MMIF related key-value pair objects.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, mmif_obj: Union[str, dict] = None):
|
|
11
|
+
"""
|
|
12
|
+
Any MMIF object can be initialized as an empty placeholder or
|
|
13
|
+
an actual representation with a JSON formatted string or equivalent
|
|
14
|
+
`dict` object argument.
|
|
15
|
+
|
|
16
|
+
:param mmif_obj: JSON string or `dict` to initialize an object.
|
|
17
|
+
If not given, an empty object will be initialized, sometimes with
|
|
18
|
+
an ID value automatically generated, based on its parent object.
|
|
19
|
+
"""
|
|
20
|
+
if mmif_obj is not None:
|
|
21
|
+
self.deserialize(mmif_obj)
|
|
22
|
+
|
|
23
|
+
def serialize(self, pretty: bool = False) -> str:
|
|
24
|
+
"""
|
|
25
|
+
Generates JSON-LD representation of an object.
|
|
26
|
+
|
|
27
|
+
:param pretty: If True, returns string representation with indentation.
|
|
28
|
+
:return: JSON-LD string of the object.
|
|
29
|
+
"""
|
|
30
|
+
return json.dumps(self._serialize(), indent=2 if pretty else None, cls=MmifObjectEncoder)
|
|
31
|
+
|
|
32
|
+
def _serialize(self) -> dict:
|
|
33
|
+
d = {}
|
|
34
|
+
for k, v in list(self.__dict__.items()):
|
|
35
|
+
if k.startswith('_'):
|
|
36
|
+
d[f'@{k[1:]}'] = v
|
|
37
|
+
else:
|
|
38
|
+
d[k] = v
|
|
39
|
+
return d
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def _load_str(json_str: str):
|
|
43
|
+
"""
|
|
44
|
+
Turns JSON-format string into python dict. In doing so, it replaces "@"
|
|
45
|
+
signs in JSON-LD field names with "_" to be python-compliant.
|
|
46
|
+
|
|
47
|
+
>>> "_type" in MmifObject._load_str('{ "@type": "some_type", "@value": "some_value"}').keys()
|
|
48
|
+
True
|
|
49
|
+
>>> "_value" in MmifObject._load_str('{ "@type": "some_type", "@value": "some_value"}').keys()
|
|
50
|
+
True
|
|
51
|
+
|
|
52
|
+
:param json_str:
|
|
53
|
+
:return:
|
|
54
|
+
"""
|
|
55
|
+
def to_atsign(d: Dict[str, Any]):
|
|
56
|
+
for k in list(d.keys()):
|
|
57
|
+
if k.startswith('@'):
|
|
58
|
+
d[f'_{k[1:]}'] = d.pop(k)
|
|
59
|
+
return d
|
|
60
|
+
return json.loads(json_str, object_hook=to_atsign)
|
|
61
|
+
|
|
62
|
+
def deserialize(self, mmif_json: Union[str, dict]) -> None:
|
|
63
|
+
"""
|
|
64
|
+
Takes a JSON-formatted string or a simple `dict` that's json-loaded from
|
|
65
|
+
such a string as an input and populates object's fields with the values
|
|
66
|
+
specified in the input.
|
|
67
|
+
NB: this assumes when input is dict type, the keys are properly renamed
|
|
68
|
+
(@xxx -> _xxx)
|
|
69
|
+
|
|
70
|
+
:param mmif_json: JSON-formatted string or dict from such a string
|
|
71
|
+
that represents a MMIF object
|
|
72
|
+
"""
|
|
73
|
+
if type(mmif_json) == str:
|
|
74
|
+
mmif_json = self._load_str(mmif_json)
|
|
75
|
+
self._deserialize(mmif_json)
|
|
76
|
+
|
|
77
|
+
def _deserialize(self, input_dict: dict) -> None:
|
|
78
|
+
"""
|
|
79
|
+
Maps a plain python dict object to a MMIF object.
|
|
80
|
+
If a subclass needs special treatment during the mapping, it needs to
|
|
81
|
+
override this method.
|
|
82
|
+
:param input_dict:
|
|
83
|
+
:return:
|
|
84
|
+
"""
|
|
85
|
+
self.__dict__ = input_dict
|
|
86
|
+
|
|
87
|
+
def __str__(self):
|
|
88
|
+
return self.serialize(False)
|
|
89
|
+
|
|
90
|
+
def pretty(self) -> str:
|
|
91
|
+
"""
|
|
92
|
+
Call :func: .serialize() with indentation.
|
|
93
|
+
"""
|
|
94
|
+
return self.serialize(True)
|
|
95
|
+
|
|
96
|
+
def __eq__(self, other):
|
|
97
|
+
return self.__dict__ == other.__dict__
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class MmifObjectEncoder(json.JSONEncoder):
|
|
101
|
+
"""
|
|
102
|
+
Encoder class to define behaviors of de-/serialization
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
def default(self, obj: 'MmifObject'):
|
|
106
|
+
"""
|
|
107
|
+
Overrides default encoding behavior to prioritize :func: MmifObject.serilize() .
|
|
108
|
+
"""
|
|
109
|
+
try:
|
|
110
|
+
return obj._serialize()
|
|
111
|
+
except:
|
|
112
|
+
return json.JSONEncoder.default(self, obj)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Dict, List, Union, Optional
|
|
3
|
+
|
|
4
|
+
from .annotation import Annotation
|
|
5
|
+
from .model import MmifObject
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class View(MmifObject):
|
|
9
|
+
id: str
|
|
10
|
+
metadata: 'ViewMetadata'
|
|
11
|
+
annotations: List['Annotation']
|
|
12
|
+
anno_ids = set()
|
|
13
|
+
|
|
14
|
+
def __init__(self, view_obj: Union[str, dict] = None):
|
|
15
|
+
self.id = ''
|
|
16
|
+
self.metadata = ViewMetadata()
|
|
17
|
+
self.annotations = []
|
|
18
|
+
super().__init__(view_obj)
|
|
19
|
+
|
|
20
|
+
def _deserialize(self, view_dict: dict):
|
|
21
|
+
self.id = view_dict['id']
|
|
22
|
+
self.metadata = ViewMetadata(view_dict['metadata'])
|
|
23
|
+
for anno_dict in view_dict['annotations']:
|
|
24
|
+
self.add_annotation(Annotation(anno_dict))
|
|
25
|
+
|
|
26
|
+
def new_contain(self, at_type: str, contain_dict: dict):
|
|
27
|
+
return self.metadata.new_contain(at_type, contain_dict)
|
|
28
|
+
|
|
29
|
+
def new_annotation(self, aid: str, at_type: str):
|
|
30
|
+
new_annotation = Annotation()
|
|
31
|
+
new_annotation.at_type = at_type
|
|
32
|
+
new_annotation.id = aid
|
|
33
|
+
return self.add_annotation(new_annotation)
|
|
34
|
+
|
|
35
|
+
def add_annotation(self, annotation: 'Annotation') -> 'Annotation':
|
|
36
|
+
self.annotations.append(annotation)
|
|
37
|
+
self.anno_ids.add(annotation.id)
|
|
38
|
+
return annotation
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ViewMetadata(MmifObject):
|
|
42
|
+
medium: str
|
|
43
|
+
timestamp: Optional[datetime] = None
|
|
44
|
+
tool: str
|
|
45
|
+
contains: Dict[str, 'Contain']
|
|
46
|
+
|
|
47
|
+
def __init__(self, viewmetadata_obj: Union[str, dict] = None):
|
|
48
|
+
self.medium = ''
|
|
49
|
+
self.timestamp = datetime.now()
|
|
50
|
+
self.tool = ''
|
|
51
|
+
self.contains = {}
|
|
52
|
+
super().__init__(viewmetadata_obj)
|
|
53
|
+
|
|
54
|
+
def _deserialize(self, input_dict: dict) -> None:
|
|
55
|
+
self.__dict__ = input_dict
|
|
56
|
+
self.contains = dict([(at_type, Contain(contain_obj)) for at_type, contain_obj in input_dict.get('contains').items()])
|
|
57
|
+
|
|
58
|
+
def new_contain(self, at_type: str, contain_dict: dict):
|
|
59
|
+
new_contain = Contain(contain_dict)
|
|
60
|
+
self.contains[at_type] = new_contain
|
|
61
|
+
return new_contain
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Contain(MmifObject):
|
|
65
|
+
producer: str
|
|
66
|
+
gen_time: datetime
|
|
67
|
+
|
|
68
|
+
def __init__(self, contain_obj: Union[str, dict] = None):
|
|
69
|
+
self.producer = ''
|
|
70
|
+
self.gen_time = datetime.now() # datetime.datetime
|
|
71
|
+
super().__init__(contain_obj)
|
|
72
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
{mmif-python-0.0.1 → usr/lib/python3.8/site-packages/mmif_python-0.1.0-py3.8.egg-info}/PKG-INFO
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mmif-python
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.1.0
|
|
4
4
|
Summary: Python implementation of MultiMedia Interchange Format specification. (https://mmif.clams.ai)
|
|
5
|
-
Home-page: https://
|
|
5
|
+
Home-page: https://mmif.clams.ai
|
|
6
6
|
Author: Brandeis Lab for Linguistics and Computation
|
|
7
7
|
Author-email: admin@clams.ai
|
|
8
8
|
License: UNKNOWN
|
|
@@ -31,3 +31,4 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
31
31
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
32
32
|
Requires-Python: >=3.6
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
34
|
+
Provides-Extra: dev
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
requirements.txt
|
|
3
|
+
setup.py
|
|
4
|
+
mmif/__init__.py
|
|
5
|
+
mmif/res/__init__.py
|
|
6
|
+
mmif/serialize/__init__.py
|
|
7
|
+
mmif/serialize/annotation.py
|
|
8
|
+
mmif/serialize/medium.py
|
|
9
|
+
mmif/serialize/mmif.py
|
|
10
|
+
mmif/serialize/model.py
|
|
11
|
+
mmif/serialize/view.py
|
|
12
|
+
mmif/ver/__init__.py
|
|
13
|
+
mmif/vocab/__init__.py
|
|
14
|
+
mmif_python.egg-info/PKG-INFO
|
|
15
|
+
mmif_python.egg-info/SOURCES.txt
|
|
16
|
+
mmif_python.egg-info/dependency_links.txt
|
|
17
|
+
mmif_python.egg-info/requires.txt
|
|
18
|
+
mmif_python.egg-info/top_level.txt
|
|
19
|
+
tests/mmif_examples.py
|
|
20
|
+
tests/test_serialize.py
|
mmif-python-0.0.1/README.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# MMIF for python
|
|
2
|
-
|
|
3
|
-
**NOTE** that this project is in pre-alpha and being actively developed. Nothing is guaranteed to reliably work for the moment and developer need to be very careful when using APIs implemented here. Please use [the issue track](../../issues) to report bugs and malfunctions, or send pull requests for even more contribution.
|
|
4
|
-
|
|
5
|
-
## MultiMedia Interchange Format
|
|
6
|
-
[MMIF](htts://mmif.clams.ai) is a JSON-LD based data format designed for transfer annotation data between computational analysis applications in [CLAMS project](https://www.clams.ai).
|
|
7
|
-
|
|
8
|
-
## installation:
|
|
9
|
-
Package `mmif-python` is distributed via the official pypi. Users are supposed to pip-install to get latest release.
|
|
10
|
-
```
|
|
11
|
-
pip install mmif-python
|
|
12
|
-
```
|
|
13
|
-
This will install a packge `mmif` to local python
|
|
14
|
-
|
|
15
|
-
## APIs
|
|
16
|
-
|
|
17
|
-
TBD
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import datetime
|
|
2
|
-
import json
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class MmifObject(object):
|
|
6
|
-
def __init__(self, mmif_json=None):
|
|
7
|
-
if mmif_json is not None:
|
|
8
|
-
self.deserialize(mmif_json)
|
|
9
|
-
|
|
10
|
-
def serialize(self):
|
|
11
|
-
return self.__dict__
|
|
12
|
-
|
|
13
|
-
def deserialize(self, mmif):
|
|
14
|
-
raise NotImplementedError()
|
|
15
|
-
|
|
16
|
-
def __str__(self):
|
|
17
|
-
return json.dumps(self.serialize(), cls=MmifObjectEncoder)
|
|
18
|
-
|
|
19
|
-
def pretty(self):
|
|
20
|
-
return json.dumps(self, indent=2, cls=MmifObjectEncoder)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class MmifObjectEncoder(json.JSONEncoder):
|
|
24
|
-
def default(self, obj):
|
|
25
|
-
if hasattr(obj, 'serialize'):
|
|
26
|
-
return obj.serialize()
|
|
27
|
-
elif hasattr(obj, '__str__'):
|
|
28
|
-
return str(obj)
|
|
29
|
-
else:
|
|
30
|
-
return json.JSONEncoder.default(self, obj)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class Mmif(MmifObject):
|
|
34
|
-
context: str
|
|
35
|
-
metadata: dict
|
|
36
|
-
media: list
|
|
37
|
-
contains: dict
|
|
38
|
-
views: list
|
|
39
|
-
|
|
40
|
-
def __init__(self, mmif_json=None):
|
|
41
|
-
self.context = ''
|
|
42
|
-
self.metadata = {}
|
|
43
|
-
self.media = []
|
|
44
|
-
self.contains = {}
|
|
45
|
-
self.views = []
|
|
46
|
-
super().__init__(mmif_json)
|
|
47
|
-
|
|
48
|
-
def serialize(self):
|
|
49
|
-
d = self.__dict__.copy()
|
|
50
|
-
d['@context'] = d.pop('context')
|
|
51
|
-
return d
|
|
52
|
-
|
|
53
|
-
def deserialize(self, mmif):
|
|
54
|
-
in_json = json.loads(mmif)
|
|
55
|
-
|
|
56
|
-
# TODO (krim @ 10/3/2018): more robust json parsing
|
|
57
|
-
self.context = in_json["@context"]
|
|
58
|
-
self.contains = in_json["contains"]
|
|
59
|
-
self.metadata = in_json["metadata"]
|
|
60
|
-
self.media = in_json["media"]
|
|
61
|
-
self.views = in_json["views"]
|
|
62
|
-
|
|
63
|
-
def new_view_id(self):
|
|
64
|
-
return 'v_' + str(len(self.views))
|
|
65
|
-
|
|
66
|
-
def new_view(self):
|
|
67
|
-
new_view = View(self.new_view_id())
|
|
68
|
-
self.views.append(new_view)
|
|
69
|
-
return new_view
|
|
70
|
-
|
|
71
|
-
def add_media(self, medium):
|
|
72
|
-
try:
|
|
73
|
-
self.get_medium_location(medium)
|
|
74
|
-
# TODO (krim @ 10/7/2018): if get_m_location returns, raise "already exists" error
|
|
75
|
-
except Exception:
|
|
76
|
-
self.media.append(medium)
|
|
77
|
-
|
|
78
|
-
def get_medium_location(self, md_type):
|
|
79
|
-
for medium in self.media:
|
|
80
|
-
if medium["type"] == md_type:
|
|
81
|
-
return medium["location"]
|
|
82
|
-
raise Exception("{} type media not found".format(md_type))
|
|
83
|
-
|
|
84
|
-
def get_view_by_id(self, id):
|
|
85
|
-
for view in self.views:
|
|
86
|
-
if view.id == id:
|
|
87
|
-
return view
|
|
88
|
-
raise Exception("{} view not found".format(id))
|
|
89
|
-
|
|
90
|
-
def get_view_contains(self, attype):
|
|
91
|
-
return self.get_view_by_id(self.contains[attype])
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
class Medium(MmifObject):
|
|
95
|
-
id: str
|
|
96
|
-
type: str
|
|
97
|
-
location: str
|
|
98
|
-
metadata: dict
|
|
99
|
-
|
|
100
|
-
def __init__(self, id, md_type='', uri=''):
|
|
101
|
-
self.id = id
|
|
102
|
-
self.type = md_type
|
|
103
|
-
self.location = uri
|
|
104
|
-
self.metadata = {}
|
|
105
|
-
|
|
106
|
-
def deserialize(self, mmif):
|
|
107
|
-
pass
|
|
108
|
-
|
|
109
|
-
def add_metadata(self, name, value):
|
|
110
|
-
self.metadata[name] = value
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
class Annotation(MmifObject):
|
|
114
|
-
start: int
|
|
115
|
-
end: int
|
|
116
|
-
feature: dict
|
|
117
|
-
id: str
|
|
118
|
-
attype: str
|
|
119
|
-
|
|
120
|
-
def __init__(self, id, at_type=''):
|
|
121
|
-
# TODO (krim @ 10/4/2018): try deserialize "id", then if fails defaults to 0s
|
|
122
|
-
super().__init__()
|
|
123
|
-
self.start = 0
|
|
124
|
-
self.end = 0
|
|
125
|
-
self.feature = {}
|
|
126
|
-
self.id = id
|
|
127
|
-
self.attype = at_type
|
|
128
|
-
|
|
129
|
-
def deserialize(self, mmif):
|
|
130
|
-
pass
|
|
131
|
-
|
|
132
|
-
def add_feature(self, name, value):
|
|
133
|
-
self.feature[name] = value
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
class View(MmifObject):
|
|
137
|
-
id: str
|
|
138
|
-
contains: dict
|
|
139
|
-
annotation: list
|
|
140
|
-
|
|
141
|
-
def __init__(self, id="UNIDENTIFIED"):
|
|
142
|
-
super().__init__()
|
|
143
|
-
self.id = id
|
|
144
|
-
self.contains = {}
|
|
145
|
-
self.annotations = []
|
|
146
|
-
|
|
147
|
-
def deserialize(self, view):
|
|
148
|
-
pass
|
|
149
|
-
|
|
150
|
-
def new_contain(self, at_type, producer=""):
|
|
151
|
-
new_contain = Contain()
|
|
152
|
-
new_contain.gen_time = datetime.datetime.utcnow().isoformat()
|
|
153
|
-
self.contains[at_type] = new_contain
|
|
154
|
-
return new_contain
|
|
155
|
-
|
|
156
|
-
def new_annotation(self, aid):
|
|
157
|
-
new_annotation = Annotation(aid)
|
|
158
|
-
self.annotations.append(new_annotation)
|
|
159
|
-
return new_annotation
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
class Contain(MmifObject):
|
|
163
|
-
producer: str
|
|
164
|
-
gen_time: str
|
|
165
|
-
|
|
166
|
-
def __init__(self):
|
|
167
|
-
super().__init__()
|
|
168
|
-
self.producer = ''
|
|
169
|
-
self.gen_time = None # datetime.datetime
|
|
170
|
-
|
|
171
|
-
def deserialize(self, mmif):
|
|
172
|
-
pass
|
|
173
|
-
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: mmif-python
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: Python implementation of MultiMedia Interchange Format specification. (https://mmif.clams.ai)
|
|
5
|
-
Home-page: https://github.com/clamsproject/mmif-python
|
|
6
|
-
Author: Brandeis Lab for Linguistics and Computation
|
|
7
|
-
Author-email: admin@clams.ai
|
|
8
|
-
License: UNKNOWN
|
|
9
|
-
Description: # MMIF for python
|
|
10
|
-
|
|
11
|
-
**NOTE** that this project is in pre-alpha and being actively developed. Nothing is guaranteed to reliably work for the moment and developer need to be very careful when using APIs implemented here. Please use [the issue track](../../issues) to report bugs and malfunctions, or send pull requests for even more contribution.
|
|
12
|
-
|
|
13
|
-
## MultiMedia Interchange Format
|
|
14
|
-
[MMIF](htts://mmif.clams.ai) is a JSON-LD based data format designed for transfer annotation data between computational analysis applications in [CLAMS project](https://www.clams.ai).
|
|
15
|
-
|
|
16
|
-
## installation:
|
|
17
|
-
Package `mmif-python` is distributed via the official pypi. Users are supposed to pip-install to get latest release.
|
|
18
|
-
```
|
|
19
|
-
pip install mmif-python
|
|
20
|
-
```
|
|
21
|
-
This will install a packge `mmif` to local python
|
|
22
|
-
|
|
23
|
-
## APIs
|
|
24
|
-
|
|
25
|
-
TBD
|
|
26
|
-
|
|
27
|
-
Platform: UNKNOWN
|
|
28
|
-
Classifier: Development Status :: 2 - Pre-Alpha
|
|
29
|
-
Classifier: Intended Audience :: Developers
|
|
30
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
31
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
32
|
-
Requires-Python: >=3.6
|
|
33
|
-
Description-Content-Type: text/markdown
|
mmif-python-0.0.1/setup.cfg
DELETED
mmif-python-0.0.1/setup.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import setuptools
|
|
2
|
-
|
|
3
|
-
with open('README.md') as readme:
|
|
4
|
-
long_desc = readme.read()
|
|
5
|
-
|
|
6
|
-
setuptools.setup(
|
|
7
|
-
name="mmif-python",
|
|
8
|
-
version="0.0.1",
|
|
9
|
-
author="Brandeis Lab for Linguistics and Computation",
|
|
10
|
-
author_email="admin@clams.ai",
|
|
11
|
-
description="Python implementation of MultiMedia Interchange Format specification. (https://mmif.clams.ai)",
|
|
12
|
-
long_description=long_desc,
|
|
13
|
-
long_description_content_type="text/markdown",
|
|
14
|
-
url="https://github.com/clamsproject/mmif-python",
|
|
15
|
-
packages=setuptools.find_packages() ,
|
|
16
|
-
python_requires='>=3.6',
|
|
17
|
-
classifiers=[
|
|
18
|
-
'Development Status :: 2 - Pre-Alpha',
|
|
19
|
-
'Intended Audience :: Developers ',
|
|
20
|
-
'License :: OSI Approved :: Apache Software License',
|
|
21
|
-
'Programming Language :: Python :: 3 :: Only',
|
|
22
|
-
],
|
|
23
|
-
)
|
|
File without changes
|
|
File without changes
|