Skip to content

Commit

Permalink
Merge pull request #133 from pyscal/parse_descriptions
Browse files Browse the repository at this point in the history
Parse descriptions
  • Loading branch information
srmnitc authored Jul 10, 2024
2 parents 6a056be + 0c0308b commit e57bb83
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.2
current_version = 0.9.3
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ url: 'https://atomrdf.pyscal.org'
license: "MIT"
repository-code: https://github.com/pyscal/atomRDF
type: software
version: 0.9.2
version: 0.9.3
15 changes: 15 additions & 0 deletions atomrdf/network/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ def _recheck_namespaces(self):
key
].namespace_with_prefix

def _add_info(self, term, c):
try:
term.description = c.IAO_0000115
except:
term.description = ""
try:
term.label = c.label
except:
term.label = ""
return term

def _parse_data_property(self):
for c in self.tree.data_properties():
iri = c.iri
Expand Down Expand Up @@ -120,6 +131,8 @@ def _parse_data_property(self):
term.domain = dm
term.range = rn
term.node_type = "data_property"
term = self._add_info(term, c)

self.attributes["data_property"][term.name] = term
# assign this data
for d in dm:
Expand Down Expand Up @@ -161,6 +174,7 @@ def _parse_object_property(self):
term = OntoTerm(iri, delimiter=self.delimiter)
term.domain = dm
term.range = rn
term = self._add_info(term, c)
term.node_type = "object_property"
self.attributes["object_property"][term.name] = term
for d in dm:
Expand All @@ -186,6 +200,7 @@ def _parse_class_basic(self):
subclasses.append(c)
for sb in subclasses:
term = OntoTerm(sb.iri, delimiter=self.delimiter)
term = self._add_info(term, sb)
term.node_type = "class"
self.attributes["class"][term.name] = term
subclasses = [strip_name(sb.iri, self.delimiter) for sb in subclasses]
Expand Down
54 changes: 53 additions & 1 deletion atomrdf/network/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(
data_type=None,
node_id=None,
delimiter="/",
description=None,
label=None,
):

self.uri = uri
Expand All @@ -69,6 +71,10 @@ def __init__(
self.subclasses = []
self.subproperties = []
self.delimiter = delimiter
self.description = description
self.label = label
self._description = None
self._label = None
self.is_domain_of = []
self.is_range_of = []
self._condition = None
Expand Down Expand Up @@ -98,6 +104,52 @@ def uri(self):
def uri(self, val):
self._uri = val

@property
def description(self):
"""
Get the description of the term.
Returns
-------
str
The description of the term.
"""
return self._description

@description.setter
def description(self, val):
if isinstance(val, list):
if len(val) == 0:
val = ''
elif len(val) > 1:
val = ". ".join(val)
else:
val = val[0]
self._description = val

@property
def label(self):
"""
Get the label of the term.
Returns
-------
str
The label of the term.
"""
return self._label

@label.setter
def label(self, val):
if isinstance(val, list):
if len(val) == 0:
val = ''
elif len(val) > 1:
val = ". ".join(val)
else:
val = val[0]
self._label = val

@property
def name_without_prefix(self):
"""
Expand Down Expand Up @@ -243,7 +295,7 @@ def toPython(self):
return self.uri

def __repr__(self):
return str(self.name)
return str(self.name + '\n' + self.description)

def _clean_datatype(self, r):
if r == "str":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='atomrdf',
version='0.9.2',
version='0.9.3',
author='Abril Azocar Guzman, Sarath Menon',
author_email='[email protected]',
description='Ontology based structural manipulation and quering',
Expand Down

0 comments on commit e57bb83

Please sign in to comment.