Exemple #1
0
    def fetch(self, entity_name):
        u = self._get_access_url(entity_name)
        requests_session = requests.session()
        requests_session.mount('file://', LocalFileAdapter())
        requests_session.mount('file:///', LocalFileAdapter())
        r = requests_session.get(u,
                                 headers=self.headers,
                                 allow_redirects=True,
                                 stream=True)
        np = nanopub.Nanopublication()
        if 'content-disposition' in r.headers:
            d = r.headers['content-disposition']
            fname = re.findall("filename=(.+)", d)
        else:
            fname = entity_name.split('/')[-1]
        content_type = r.headers.get('content-type')

        if self.file_types is not None:
            for file_type in file_types:
                np.assertion.add((entity_name, rdflib.RDF.type, file_type))
        f = FileStorage(FileLikeFromIter(r.iter_content()),
                        fname,
                        content_type=content_type)
        old_nanopubs = self.app.add_file(f, entity_name, np)
        np.assertion.add(
            (entity_name, self.app.NS.RDF.type, self.app.NS.pv.File))
        for old_np, old_np_assertion in old_nanopubs:
            np.pubinfo.add((np.assertion.identifier,
                            self.app.NS.prov.wasRevisionOf, old_np_assertion))

        return np
    def test_L102_S3_Hu_2007(self):
        self.login(*self.create_user("*****@*****.**", "password"))
        text = "Hello, World!"
        b64text = b64encode(text)
        nanopub = files['L102_S3_Hu_2007']
        response = self.client.post("/pub",
                                    data=nanopub,
                                    content_type="application/ld+json",
                                    follow_redirects=True)

        self.assertEquals(response.status, '201 CREATED')
        content = self.client.get(
            "/about",
            query_string={"uri": "http://example.com/testdatab64"},
            follow_redirects=True)
        self.assertEquals(content.mimetype, "text/plain")
        self.assertEquals(content.data, text)

        np = nanopub.Nanopublication()
        np.assertion.parse(data=open('../setl/xml_ingest.setl.ttl'),
                           format="turtle")
        setlmaker = autonomic.SETLMaker()

        results = self.run_agent(setlmaker, nanopublication=np)

        # confirm this is creating a SETL script for the XML file.

        setlr = autonomic.SETLr()

        for nanopub in results:
            setlr_results = self.run_agent(setlr, nanopublication=nanopub)
Exemple #3
0
    def test_hasco_import(self):
        np = nanopub.Nanopublication()
        np.assertion.parse(data='''{
         "@id": "http://example.com/testonto",
         "@type" : "http://www.w3.org/2002/07/owl#Ontology",
         "http://www.w3.org/2002/07/owl#imports":{"@id":"http://hadatac.org/ont/hasco/"}
        }''',
                           format="json-ld")
        agent = autonomic.OntologyImporter()

        results = self.run_agent(agent, nanopublication=np)
        self.assertEquals(len(results), 1)
        self.assertTrue(results[0].resource(
            URIRef('http://hadatac.org/ont/hasco/'))[RDF.type:OWL.Ontology])
Exemple #4
0
    def test_dc_terms_import(self):
        np = nanopub.Nanopublication()
        np.assertion.parse(data='''{
         "@id": "http://example.com/testonto",
         "@type" : "http://www.w3.org/2002/07/owl#Ontology",
         "http://www.w3.org/2002/07/owl#imports":{"@id":"http://purl.org/dc/terms/"}
        }''',
                           format="json-ld")
        agent = autonomic.OntologyImporter()

        results = self.run_agent(agent, nanopublication=np)
        self.assertEquals(len(results), 1)
        print results[0].serialize(format="trig")
        self.assertTrue(results[0].resource(
            URIRef('http://purl.org/dc/terms/created'))[RDF.type:RDF.Property])
Exemple #5
0
    def test_dc_terms_import(self):
        np = nanopub.Nanopublication()
        np.assertion.parse(data=str(
            '''<http://example.com/testonto> a <http://www.w3.org/2002/07/owl#Ontology>;
         <http://www.w3.org/2002/07/owl#imports> <http://purl.org/dc/terms/>.'''
        ),
                           format="turtle")
        #print(np.serialize(format="trig"))
        agent = autonomic.OntologyImporter()

        results = self.run_agent(agent, nanopublication=np)
        self.assertEquals(len(results), 1)
        #print(results[0].serialize(format="trig"))
        self.assertTrue(results[0].resource(
            URIRef('http://purl.org/dc/terms/created'))[RDF.type:RDF.Property])
Exemple #6
0
    def test_prov_import(self):
        np = nanopub.Nanopublication()
        np.assertion.parse(data='''{
         "@id": "http://example.com/testonto",
         "@type" : "http://www.w3.org/2002/07/owl#Ontology",
         "http://www.w3.org/2002/07/owl#imports":{"@id":"http://www.w3.org/ns/prov#"}
        }''',
                           format="json-ld")
        #print(np.serialize(format="trig"))
        agent = autonomic.OntologyImporter()

        results = self.run_agent(agent, nanopublication=np)
        self.assertEquals(len(results), 1)
        self.assertTrue(len(results[0]) > 0)
        self.assertTrue(results[0].resource(
            URIRef('http://www.w3.org/ns/prov#'))[RDF.type:OWL.Ontology])
Exemple #7
0
    def process(self, i, o):
        document_count = float(self.document_count)
        
        query = """select distinct ?concept (count(distinct ?othernode) as ?count) ?assertion where {
  ?node sio:hasPart [ a sio:Term; prov:specializationOf ?concept].
  ?othernode sio:hasPart [ a sio:Term; prov:specializationOf ?concept].
  optional {
    graph ?assertion {
        ?concept sio:InverseDocumentFrequency ?idf.
    }
  }
} group by ?concept ?assertion"""
        for concept, count, assertion in self.app.db.query(query, initBindings=dict(node=i.identifier)):
            idf = log10(old_div(document_count,count.value))
            npub = nanopub.Nanopublication(store=o.graph.store)
            if assertion is not None:
                npub.pubinfo.add((npub.assertion.identifier, prov.wasRevisionOf, assertion))
            npub.assertion.add((concept, sio.InverseDocumentFrequency, Literal(idf)))