Skip to content

Commit

Permalink
datatype is always present (default to XSD.string)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelo7 committed Oct 19, 2024
1 parent 60dd95d commit 8edb0fe
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 69 deletions.
2 changes: 1 addition & 1 deletion oc_ocdm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
__version__ = '7.0.1'
__version__ = '9.1.1'

from oc_ocdm.storer import Storer
from oc_ocdm.reader import Reader
3 changes: 1 addition & 2 deletions oc_ocdm/graph/graph_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

from typing import TYPE_CHECKING

from rdflib import Graph, Namespace, URIRef

from oc_ocdm.abstract_entity import AbstractEntity
from rdflib import Graph, Namespace, URIRef

if TYPE_CHECKING:
from typing import ClassVar, Dict, List, Optional, Tuple
Expand Down
8 changes: 3 additions & 5 deletions oc_ocdm/graph/graph_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@

from typing import TYPE_CHECKING

from SPARQLWrapper import RDFXML, SPARQLWrapper

from oc_ocdm.abstract_set import AbstractSet
from oc_ocdm.reader import Reader
from oc_ocdm.support.support import get_count, get_short_name, get_prefix
from oc_ocdm.support.support import get_count, get_prefix, get_short_name
from SPARQLWrapper import RDFXML, SPARQLWrapper

if TYPE_CHECKING:
from typing import Dict, ClassVar, Tuple, Optional, List, Set
from rdflib import ConjunctiveGraph

from rdflib import Graph, Namespace, URIRef

from oc_ocdm.counter_handler.counter_handler import CounterHandler
from oc_ocdm.counter_handler.filesystem_counter_handler import \
FilesystemCounterHandler
Expand All @@ -53,6 +50,7 @@
ResponsibleAgent
from oc_ocdm.graph.entities.identifier import Identifier
from oc_ocdm.graph.graph_entity import GraphEntity
from rdflib import Graph, Namespace, URIRef


class GraphSet(AbstractSet):
Expand Down
7 changes: 3 additions & 4 deletions oc_ocdm/storer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
from typing import TYPE_CHECKING
from zipfile import ZIP_DEFLATED, ZipFile

from rdflib import ConjunctiveGraph, URIRef
from SPARQLWrapper import SPARQLWrapper

from filelock import FileLock
from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.metadata.metadata_entity import MetadataEntity
from oc_ocdm.prov.prov_entity import ProvEntity
from oc_ocdm.reader import Reader
from oc_ocdm.support.query_utils import get_update_query
from oc_ocdm.support.reporter import Reporter
from oc_ocdm.support.support import find_paths
from filelock import FileLock
from rdflib import ConjunctiveGraph, URIRef
from SPARQLWrapper import SPARQLWrapper

if TYPE_CHECKING:
from typing import Any, Dict, List, Optional, Set, Tuple
Expand Down
3 changes: 2 additions & 1 deletion oc_ocdm/support/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def encode_url(u: str) -> str:

def create_literal(g: Graph, res: URIRef, p: URIRef, s: str, dt: URIRef = None, nor: bool = True) -> None:
if not is_string_empty(s):
dt = dt if dt is not None else XSD.string
g.add((res, p, Literal(s, datatype=dt, normalize=nor)))


Expand Down Expand Up @@ -371,7 +372,7 @@ def build_graph_from_results(results: List[Dict]) -> Graph:
o = URIRef(triple['o']['value'])
else:
datatype = triple['o'].get('datatype', None)
datatype = URIRef(datatype) if datatype is not None else None
datatype = URIRef(datatype) if datatype is not None else XSD.string
o = Literal(triple['o']['value'], datatype=datatype)
graph.add((s, p, o))
return graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# SOFTWARE.
import unittest

from rdflib import Literal

from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.graph.graph_set import GraphSet
from rdflib import XSD, Literal


class TestBibliographicReference(unittest.TestCase):
Expand All @@ -38,7 +37,7 @@ def test_has_content(self):
result = self.be.has_content(content)
self.assertIsNone(result)

triple = self.be.res, GraphEntity.iri_has_content, Literal(content)
triple = self.be.res, GraphEntity.iri_has_content, Literal(content, datatype=XSD.string)
self.assertIn(triple, self.be.g)

def test_has_annotation(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def test_has_title(self):
result = self.br1.has_title(title)
self.assertIsNone(result)

triple = self.br1.res, GraphEntity.iri_title, Literal(title)
triple = self.br1.res, GraphEntity.iri_title, Literal(title, datatype=XSD.string)
self.assertIn(triple, self.br1.g)

def test_has_subtitle(self):
subtitle = "Resource"
result = self.br1.has_subtitle(subtitle)
self.assertIsNone(result)

triple = self.br1.res, GraphEntity.iri_has_subtitle, Literal(subtitle)
triple = self.br1.res, GraphEntity.iri_has_subtitle, Literal(subtitle, datatype=XSD.string)
self.assertIn(triple, self.br1.g)

def test_is_part_of(self):
Expand Down Expand Up @@ -107,15 +107,15 @@ def test_create_number(self):
result = self.br1.has_number(number)
self.assertIsNone(result)

triple = self.br1.res, GraphEntity.iri_has_sequence_identifier, Literal(number)
triple = self.br1.res, GraphEntity.iri_has_sequence_identifier, Literal(number, datatype=XSD.string)
self.assertIn(triple, self.br1.g)

def test_has_edition(self):
edition = "abcde"
result = self.br1.has_edition(edition)
self.assertIsNone(result)

triple = self.br1.res, GraphEntity.iri_has_edition, Literal(edition)
triple = self.br1.res, GraphEntity.iri_has_edition, Literal(edition, datatype=XSD.string)
self.assertIn(triple, self.br1.g)

def test_contains_in_reference_list(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# SOFTWARE.
import unittest

from rdflib import Literal, RDF

from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.graph.graph_set import GraphSet
from rdflib import RDF, XSD, Literal


class TestDiscourseElement(unittest.TestCase):
Expand All @@ -39,7 +38,7 @@ def test_has_title(self):
result = self.de1.has_title(title)
self.assertIsNone(result)

triple = self.de1.res, GraphEntity.iri_title, Literal(title)
triple = self.de1.res, GraphEntity.iri_title, Literal(title, datatype=XSD.string)
self.assertIn(triple, self.de1.g)

def test_contains_discourse_element(self):
Expand Down Expand Up @@ -75,7 +74,7 @@ def test_has_content(self):
result = self.de1.has_content(content)
self.assertIsNone(result)

triple = self.de1.res, GraphEntity.iri_has_content, Literal(content)
triple = self.de1.res, GraphEntity.iri_has_content, Literal(content, datatype=XSD.string)
self.assertIn(triple, self.de1.g)

def test_create_section(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# SOFTWARE.
import unittest

from rdflib import Literal

from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.graph.graph_set import GraphSet
from rdflib import XSD, Literal


class TestPointerList(unittest.TestCase):
Expand All @@ -37,7 +36,7 @@ def test_has_content(self):
result = self.pl.has_content(content)
self.assertIsNone(result)

triple = self.pl.res, GraphEntity.iri_has_content, Literal(content)
triple = self.pl.res, GraphEntity.iri_has_content, Literal(content, datatype=XSD.string)
self.assertIn(triple, self.pl.g)

def test_contains_element(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# SOFTWARE.
import unittest

from rdflib import Literal

from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.graph.graph_set import GraphSet
from rdflib import XSD, Literal


class TestReferencePointer(unittest.TestCase):
Expand All @@ -39,7 +38,7 @@ def test_has_content(self):
result = self.rp1.has_content(content)
self.assertIsNone(result)

triple = self.rp1.res, GraphEntity.iri_has_content, Literal(content)
triple = self.rp1.res, GraphEntity.iri_has_content, Literal(content, datatype=XSD.string)
self.assertIn(triple, self.rp1.g)

def test_has_next_rp(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# SOFTWARE.
import unittest

from rdflib import URIRef, Literal, RDF

from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.graph.graph_set import GraphSet
from rdflib import RDF, XSD, Literal, URIRef


class TestResourceEmbodiment(unittest.TestCase):
Expand All @@ -44,15 +43,15 @@ def test_has_starting_page(self):
result = self.re.has_starting_page(starting_page)
self.assertIsNone(result)

triple = self.re.res, GraphEntity.iri_starting_page, Literal(starting_page)
triple = self.re.res, GraphEntity.iri_starting_page, Literal(starting_page, datatype=XSD.string)
self.assertIn(triple, self.re.g)

def test_has_ending_page(self):
ending_page = "288"
result = self.re.has_ending_page(ending_page)
self.assertIsNone(result)

triple = self.re.res, GraphEntity.iri_ending_page, Literal(ending_page)
triple = self.re.res, GraphEntity.iri_ending_page, Literal(ending_page, datatype=XSD.string)
self.assertIn(triple, self.re.g)

def test_has_url(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
# SOFTWARE.
import unittest

from rdflib import Literal, URIRef

from oc_ocdm.graph.graph_entity import GraphEntity
from oc_ocdm.graph.graph_set import GraphSet
from rdflib import XSD, Literal, URIRef


class TestResponsibleAgent(unittest.TestCase):
Expand All @@ -37,23 +36,23 @@ def test_has_name(self):
result = self.ra.has_name(name)
self.assertIsNone(result)

triple = self.ra.res, GraphEntity.iri_name, Literal(name)
triple = self.ra.res, GraphEntity.iri_name, Literal(name, datatype=XSD.string)
self.assertIn(triple, self.ra.g)

def test_has_given_name(self):
given_name = "GivenName"
result = self.ra.has_given_name(given_name)
self.assertIsNone(result)

triple = self.ra.res, GraphEntity.iri_given_name, Literal(given_name)
triple = self.ra.res, GraphEntity.iri_given_name, Literal(given_name, datatype=XSD.string)
self.assertIn(triple, self.ra.g)

def test_has_family_name(self):
family_name = "GivenName"
result = self.ra.has_family_name(family_name)
self.assertIsNone(result)

triple = self.ra.res, GraphEntity.iri_family_name, Literal(family_name)
triple = self.ra.res, GraphEntity.iri_family_name, Literal(family_name, datatype=XSD.string)
self.assertIn(triple, self.ra.g)

def test_has_related_agent(self):
Expand Down
Loading

0 comments on commit 8edb0fe

Please sign in to comment.