def citation_enhancer_view_core(enhancer_id = None, enhancer_setup = None, parent_id = None, form_id=None, parent_field=None): content = stanbol_contenthub_retrieve(parent_id, media_type="rdf", subresource="raw") additional_constraints = [{ "type": "reference", "field": str(RDF.term("type")), "value": "http://purl.uniprot.org/core/Journal_Citation" }] formtable = define_table_query_form(form_id,parent_field) formtable.query.default = remove_first_line(content) formtable.type.default = "similarity" formtable.site.default = "uniprot" formtable.field.requires = None formtable.field.default = str(RDFS.term("comment")) formtable.result_limit.default = 500 formtable.additional_constraints.default = json.dumps(additional_constraints) form = SQLFORM(formtable, submit_button='Search') form.element(_id="%s_query"%form_id).attributes["_rows"]="5" form.element(_id="%s_query"%form_id).attributes["_cols"]="120" form_hide_row(form,form_id,"additional_constraints") form_hide_row(form,form_id,"site") form_hide_row(form,form_id,"field") form_hide_row(form,form_id,"type") form_hide_row(form,form_id,"result_limit") form_hide_row(form,form_id,"mode") return form
def finalize(self): """Write add type information pred in self._predicates --> pred a owl:ObjectProperty . cls in self._classes --> cls a owl:Class . sup, sub in self._cls_hierarchy --> sub rdfs:subClassOf sup . i, cls in self._type_defs --> i a cls . p, cls in self._domains --> p rdfs:domain cls . p, cls in self._ranges --> p rdfs:range cls . """ owl_ObjectProperty = OWL.term('ObjectProperty') owl_Class = OWL.term('Class') owl_FunctionalProperty = OWL.term('FunctionalProperty') rdfs_subClassOf = RDFS.term('subClassOf') rdfs_domain = RDFS.term('domain') rdfs_range = RDFS.term('range') for pred in self._predicates: self._g.add((self._pred_uri(pred), a, owl_ObjectProperty)) for cls in self._classes: self._g.add((self._cls_uri(cls), a, owl_Class)) for super_cls, sub_clss in self._cls_hierarchy.items(): for sub_cls in sub_clss: self._g.add(( self._cls_uri(sub_cls), rdfs_subClassOf, self._cls_uri(super_cls))) for inst, classes in self._type_defs.items(): for cls in classes: self._g.add((self._res_uri(inst), a, self._cls_uri(cls))) for pred, clss in self._domains.items(): for cls in clss: self._g.add( (self._pred_uri(pred), rdfs_domain, self._cls_uri(cls))) for pred, clss in self._ranges.items(): for cls in clss: self._g.add( (self._pred_uri(pred), rdfs_range, self._cls_uri(cls))) for preds in self._nary_property_preds.values(): for pred in preds: self._g.add((self._pred_uri(pred), a, owl_FunctionalProperty))
def entityhub_find(self, query, field=RDFS.term("label"), site=None): resturl = "entityhub/site/%s/find"%site if site is not None else "entityhub/sites/find" r = self.call_stanbol("post", resturl, data = { 'name' : query, 'field': field, }) self.check_status_ok(r) return r.content
def stanbol_enhancements_view_core(enhancer_id = None, enhancer_setup = None, parent_id = None, form_id=None, parent_field=None): meta=stanbol.contenthub_retrieve(parent_id, media_type="rdf", subresource="metadata") js=stanbolmod.rdf_to_json(meta) selectedFields = dict( titlep = "http://purl.uniprot.org/core/title", title = "http://purl.org/dc/terms/title", comment = str(RDFS.term("comment")), label = str(RDFS.term("label")), mnemonic = "http://purl.uniprot.org/core/mnemonic", type = str(RDF.term("type")), ) def __getField(r,fieldList,default="id"): for f in fieldList: try: return r[selectedFields[f]][0]["value"] except: pass return r[default] enh = [] try: res = json.loads(qry) for r in res["results"]: enh.append( dict(id =r["id"], title = __getField(r,["title","titlep","label","mnemonic","type"]), description=__getField(r,["comment","type"]) ) ) except Exception as e: enh.append( dict(id=qry, title="There was an error:", description=str(e)) ) #[ # for (k,v) in js.iteritems() if not k.startswith("urn:enhancement")] #fields = [Field("E%d"%i,"string",default=url,writable=False) for (i,url) in enumerate(md)] #def_tab_args=[form_id]+fields+[parent_field] #form = SQLFORM(SQLDB(None).define_table(*def_tab_args), # submit_button='Review&Accept') return form
def get_formated_enhancements_jsonquery(jsonquery,site=None): #Useful information for enhancements selectedFields = dict( titlep = "http://purl.uniprot.org/core/title", title = "http://purl.org/dc/terms/title", comment = str(RDFS.term("comment")), label = str(RDFS.term("label")), mnemonic = "http://purl.uniprot.org/core/mnemonic", type = str(RDF.term("type")), ) jsonquery["selected"]=selectedFields.values() try: qry = stanbol.entityhub_query(jsonquery,site) except Exception as e: qry = str(e) def __getField(r,fieldList,default="id"): for f in fieldList: try: return r[selectedFields[f]][0]["value"] except: pass return r[default] enh = [] try: res = json.loads(qry) for r in res["results"]: enh.append( dict(id =r["id"], title = __getField(r,["title","titlep","label","mnemonic","type"]), description=__getField(r,["comment","type"]) ) ) except Exception as e: enh.append( dict(id=qry, title="There was an error:", description=str(e)) ) return enh
def query_enhancer_view_core(enhancer_id = None, enhancer_setup = None, parent_id = None, form_id=None, parent_field=None): content = stanbol_contenthub_retrieve(parent_id, media_type="rdf", subresource="raw") all_sites = stanbol_entityhub_sites() stanbol_important_fields = [stanbolmod.STANBOL_REFS, RDFS.term("label"),"http://purl.uniprot.org/core/title","http://purl.org/dc/terms/title", RDFS.term("comment"),RDFS.term("seeAlso")] formtable = define_table_query_form(form_id,parent_field) formtable.query.default = remove_first_line(content) formtable.site.requires = IS_IN_SET(all_sites) formtable.site.default = "uniprot" formtable.field.requires = IS_IN_SET(stanbol_important_fields) formtable.field.default = stanbolmod.STANBOL_REFS form= SQLFORM(formtable,submit_button='Search') form.element(_id="%s_query"%form_id).attributes["_rows"]="5" form.element(_id="%s_query"%form_id).attributes["_cols"]="120" return form
import inspect import os from rdflib import Graph, RDFS, RDF, OWL from itertools import chain owl_class = OWL.term('Class') owl_obj_property = OWL.term('ObjectProperty') owl_data_property = OWL.term('DatatypeProperty') rdf_type = RDF.term('type') rdfs_domain = RDFS.term('domain') rdfs_range = RDFS.term('range') rdfs_subClassOf = RDFS.term('subClassOf') def create_onto_py_URIs(file, form='turtle', add_imports=True): g = Graph() root = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) root += '/OwlFiles/' g.parse(root + file, format=form) file_content = '' if add_imports: file_content = "# Auto generated file #\n" \ "from rdflib import Graph,URIRef\n" \ "import os\n" \ "import inspect\n\n\n" \ file_content += "graph = Graph()\n" \ "root = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))\n" \ "root += '/OwlFiles/'\n" \
from rdflib import Graph from rdflib import Literal from rdflib import OWL from rdflib import RDF from rdflib import RDFS from rdflib import URIRef from rdflib import XSD from utils import write_graph a = RDF.term('type') rdfs_domain = RDFS.term('domain') rdfs_range = RDFS.term('range') rdfs_subClassOf = RDFS.term('subClassOf') xsd_double = XSD.term('double') owl_Class = OWL.term('Class') owl_DatatypeProperty = OWL.term('DatatypeProperty') owl_FunctionalProperty = OWL.term('FunctionalProperty') class Iris2RDFConverter(object): """ Attribute Information: 1. sepal length in cm 2. sepal width in cm 3. petal length in cm 4. petal width in cm 5. class: -- Iris Setosa -- Iris Versicolour
# -*- coding: utf-8 -*- import rdflib from rdflib.namespace import Namespace from rdflib import RDFS, RDF, OWL SH = Namespace('http://www.w3.org/ns/shacl#') # Classes RDF_Property = RDF.term('Property') RDF_List = RDF.term('List') RDFS_Resource = RDFS.term('Resource') RDFS_Class = RDFS.term('Class') OWL_Ontology = OWL.term("Ontology") OWL_Class = OWL.term("Class") OWL_DatatypeProperty = OWL.term("DatatypeProperty") SH_NodeShape = SH.term('NodeShape') SH_PropertyShape = SH.term('PropertyShape') SH_ValidationResult = SH.term('ValidationResult') SH_ValidationReport = SH.term('ValidationReport') SH_Violation = SH.term('Violation') SH_Info = SH.term('Info') SH_Warning = SH.term('Warning') SH_IRI = SH.term('IRI') SH_BlankNode = SH.term('BlankNode') SH_Literal = SH.term('Literal') SH_BlankNodeOrIRI = SH.term('BlankNodeOrIRI') SH_BlankNodeORLiteral = SH.term('BlankNodeOrLiteral') SH_IRIOrLiteral = SH.term('IRIOrLiteral') SH_SPARQLFunction = SH.term('SPARQLFunction') SH_SPARQLRule = SH.term('SPARQLRule')
# -*- coding: utf-8 -*- from rdflib import OWL, RDF, RDFS from rdflib.namespace import Namespace SH = Namespace('http://www.w3.org/ns/shacl#') # Classes RDF_Property = RDF.term('Property') RDF_List = RDF.term('List') RDFS_Resource = RDFS.term('Resource') RDFS_Class = RDFS.term('Class') OWL_Ontology = OWL.term("Ontology") OWL_Class = OWL.term("Class") OWL_DatatypeProperty = OWL.term("DatatypeProperty") SH_NodeShape = SH.term('NodeShape') SH_PropertyShape = SH.term('PropertyShape') SH_ValidationResult = SH.term('ValidationResult') SH_ValidationReport = SH.term('ValidationReport') SH_Violation = SH.term('Violation') SH_Info = SH.term('Info') SH_Warning = SH.term('Warning') SH_IRI = SH.term('IRI') SH_BlankNode = SH.term('BlankNode') SH_Literal = SH.term('Literal') SH_BlankNodeOrIRI = SH.term('BlankNodeOrIRI') SH_BlankNodeORLiteral = SH.term('BlankNodeOrLiteral') SH_IRIOrLiteral = SH.term('IRIOrLiteral') SH_ConstraintComponent = SH.term('ConstraintComponent') SH_SHACLFunction = SH.term('SHACLFunction') SH_SPARQLFunction = SH.term('SPARQLFunction')
# -*- coding: utf-8 -*- import rdflib from rdflib.namespace import Namespace from rdflib import RDFS, RDF, OWL SH = Namespace('http://www.w3.org/ns/shacl#') # Classes RDFS_Class = RDFS.term('Class') SH_NodeShape = SH.term('NodeShape') SH_PropertyShape = SH.term('PropertyShape') SH_ValidationResult = SH.term('ValidationResult') SH_ValidationReport = SH.term('ValidationReport') SH_Violation = SH.term('Violation') SH_Info = SH.term('Info') SH_Warning = SH.term('Warning') SH_IRI = SH.term('IRI') SH_BlankNode = SH.term('BlankNode') SH_Literal = SH.term('Literal') SH_BlankNodeOrIRI = SH.term('BlankNodeOrIRI') SH_BlankNodeORLiteral = SH.term('BlankNodeOrLiteral') SH_IRIOrLiteral = SH.term('IRIOrLiteral') # predicates RDF_type = RDF.term('type') RDFS_subClassOf = RDFS.term('subClassOf') SH_path = SH.term('path') SH_deactivated = SH.term('deactivated') SH_message = SH.term('message') SH_name = SH.term('name')
# -*- coding: utf-8 -*- # """A collection of handy utility RDF functions, will one day be split out into its own installable module.""" from rdflib import RDF, RDFS, Namespace RDFS_Resource = RDFS.term('Resource') RDF_first = RDF.term('first') SH = Namespace('http://www.w3.org/ns/shacl#') from .load import load_from_source, get_rdf_from_web from .stringify import stringify_blank_node, stringify_graph, stringify_literal, stringify_node from .clone import clone_blank_node, clone_literal, clone_graph, clone_node, mix_graphs from .compare import compare_blank_node, order_graph_literal, compare_node, compare_literal