Пример #1
0
 def test_default_namespaces(self):
     "Tests default namespaces for build_prefixes"
     prefix_tst = "PREFIX bf: <http://bibframe.org/vocab/>\n"
     prefix_tst += "PREFIX  schema: <http://schema.org/>\n"
     self.assertEqual(
         prefix_tst,
         build_prefixes())
Пример #2
0
    def process_subject(self, subject):
        """Method takes a subject URI and iterates through the subject's
        predicates and objects, saving them to a the subject's Fedora graph.
        Blank nodes are expanded and saved as properties to the subject
        graph as well. Finally, the graph is serialized as JSON-LD and updated
        in the Elastic Search index.

        Args:
            subject(rdflib.URIRef): Subject URI
        """
        fedora_url = self.bf2uris[str(subject)]
        sparql = build_prefixes(self.repository.namespaces)
        sparql += "\nINSERT DATA {\n"
        if self.debug:
            sparql += create_sparql_insert_row(
                OWL.sameAs,
                subject
            )
        for predicate, _object in self.graph.predicate_objects(subject=subject):
            if str(_object) in self.bf2uris:
                object_url = self.bf2uris[str(_object)]
                sparql += create_sparql_insert_row(
                    predicate,
                    rdflib.URIRef(object_url)
                )
            elif _object != rdflib.Literal:
                sparql += create_sparql_insert_row(
                    predicate,
                    _object)
        sparql += "\n}"
        update_fedora_request = urllib.request.Request(
            fedora_url,
            method='PATCH',
            data=sparql.encode(),
            headers={"Content-type": "application/sparql-update"})
        try:
            result = urllib.request.urlopen(update_fedora_request)
            self.index(rdflib.URIRef(fedora_url))
            return fedora_url
        except:
            print("Could NOT process subject {} Error={}".format(
                subject,
                sys.exc_info()[0]))
            print(fedora_url)
            print(sparql)
Пример #3
0
    def process_subject(self, subject):
        """Method takes a subject URI and iterates through the subject's
        predicates and objects, saving them to a the subject's Fedora graph.
        Blank nodes are expanded and saved as properties to the subject
        graph as well. Finally, the graph is serialized as JSON-LD and updated
        in the Elastic Search index.

        Args:
            subject(rdflib.URIRef): Subject URI
        """
        fedora_url = self.bf2uris[str(subject)]
        sparql = build_prefixes(self.repository.namespaces)
        sparql += "\nINSERT DATA {\n"
        if self.debug:
            sparql += create_sparql_insert_row(OWL.sameAs, subject)
        for predicate, _object in self.graph.predicate_objects(
                subject=subject):
            if str(_object) in self.bf2uris:
                object_url = self.bf2uris[str(_object)]
                sparql += create_sparql_insert_row(predicate,
                                                   rdflib.URIRef(object_url))
            elif _object != rdflib.Literal:
                sparql += create_sparql_insert_row(predicate, _object)
        sparql += "\n}"
        update_fedora_request = urllib.request.Request(
            fedora_url,
            method='PATCH',
            data=sparql.encode(),
            headers={"Content-type": "application/sparql-update"})
        try:
            result = urllib.request.urlopen(update_fedora_request)
            self.index(rdflib.URIRef(fedora_url))
            return fedora_url
        except:
            print("Could NOT process subject {} Error={}".format(
                subject,
                sys.exc_info()[0]))
            print(fedora_url)
            print(sparql)
Пример #4
0
 def test_custom_namespaces(self):
     "Tests passing in custom namespaces into function"
     self.assertEqual(
         "PREFIX bf: <http://bibframe.org/vocab/>\n",
         build_prefixes([['bf', 'http://bibframe.org/vocab/']]))
Пример #5
0
 def test_default_namespaces(self):
     "Tests default namespaces for build_prefixes"
     prefix_tst = "PREFIX bf: <http://bibframe.org/vocab/>\n"
     prefix_tst += "PREFIX  schema: <http://schema.org/>\n"
     self.assertEqual(prefix_tst, build_prefixes())
Пример #6
0
 def test_custom_namespaces(self):
     "Tests passing in custom namespaces into function"
     self.assertEqual(
         "PREFIX bf: <http://bibframe.org/vocab/>\n",
         build_prefixes(
             [['bf', 'http://bibframe.org/vocab/']]))