Skip to content

Commit

Permalink
Merge pull request #427 from usc-isi-i2/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
saggu committed Jan 29, 2021
2 parents 585060b + bddb8df commit b26cc04
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
4 changes: 3 additions & 1 deletion etk/knowledge_graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def serialize(self, format='ttl', namespace_manager=None, **kwargs):
b_string = self._g.serialize(format=format, contexts=namespace_manager, **kwargs)
else:
b_string = self._g.serialize(format=format, **kwargs)
return b_string.decode('UTF-8')
if isinstance(b_string, bytes):
b_string.decode('UTF-8')
return b_string

@lru_cache()
def _resolve_uri(self, uri: URI) -> rdflib.URIRef:
Expand Down
17 changes: 15 additions & 2 deletions etk/knowledge_graph/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import date, datetime
from xml.dom.minidom import Document, DocumentFragment
from etk.etk_exceptions import InvalidGraphNodeValueError, UnknownLiteralType

import re

class Node(object):
def __init__(self, value):
Expand Down Expand Up @@ -118,6 +118,13 @@ def __getattr__(self, item):


class LiteralType(URI, metaclass=__Type):

valid_time_pattern = re.compile(r"[\-]?(\d{4})-((0[1-9])|(1[0-2]))-(0[1-9]|[12][0-9]|3[01])T(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])")
valid_month_pattern = re.compile(r"[\-]?(\d{4})-((0[1-9])|(1[0-2]))-(00)T00:00:00")
valid_year_decade_millennium_pattern = re.compile(r"[\-]?(\d{4})-(00)-(00)T00:00:00")
valid_hundred_thousand_years_pattern = re.compile(r"[\-]?(\d{6,7})-(0[0|1])-(0[0|1])T00:00:00")
valid_million_billion_years = re.compile(r"[\-]?(\d{8}\d+)-(0[0|1])-(0[0|1])T00:00:00")

def __init__(self, s, common_check=True):
self.common_check = common_check
self._type = None
Expand Down Expand Up @@ -172,6 +179,7 @@ def is_value_valid(self, s):

@staticmethod
def _is_valid_date_time(s):

if isinstance(s, datetime):
return True

Expand All @@ -193,7 +201,12 @@ def _is_valid_date_time(s):
except:
pass

return False
validity_list = [LiteralType.valid_time_pattern.match(s),
LiteralType.valid_month_pattern.match(s),
LiteralType.valid_year_decade_millennium_pattern.match(s),
LiteralType.valid_hundred_thousand_years_pattern.match(s),
LiteralType.valid_million_billion_years.match(s)]
return any(validity_list)

xsd = 'http://www.w3.org/2001/XMLSchema#'
rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
Expand Down
7 changes: 6 additions & 1 deletion etk/wikidata/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ def __build_full_value(self):
self.full_value.add_property(URI('wikibase:timePrecision'), self._precision)
self.full_value.add_property(URI('wikibase:timeTimezone'), self._time_zone)
self.full_value.add_property(URI('wikibase:timeCalendarModel'), self._calendar.value)
self.full_value.add_property(URI('wikibase:timeValue'), self.value)
self.full_value.add_property(URI('wikibase:timeValue'), self.value)
# TODO fix import bug
# if not self.value.startswith("+"):
# self.full_value.add_property(URI('wikibase:timeValue'), self.value)
# else:
# self.full_value.add_property(URI('wikibase:timeValue'), self.value[1:])

def _v_name(self):
time = self.value.value.replace(':', '').replace(' ', '-')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setuptools.setup(
name="etk",
version="2.2.4",
version="2.2.5",
author="Amandeep Singh",
author_email="amandeep.s.saggu@gmail.com",
description="extraction toolkit",
Expand Down

0 comments on commit b26cc04

Please sign in to comment.