Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #61

Merged
merged 11 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.5
current_version = 0.1.6
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion notebooks/create_onto.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/wrap_creation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions pyscal_rdf/data/cmso.owl
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@
<owl:DatatypeProperty rdf:about="http://purls.helmholtz-metadaten.de/cmso/hasSpaceGroupSymbol">
<rdfs:subPropertyOf rdf:resource="http://purls.helmholtz-metadaten.de/cmso/hasSymbol"/>
<rdfs:domain rdf:resource="http://purls.helmholtz-metadaten.de/cmso/SpaceGroup"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:label>has space group symbol</rdfs:label>
<skos:definition>A data property linking a crystal structure with its space group symbol.</skos:definition>
</owl:DatatypeProperty>
Expand All @@ -723,6 +722,7 @@

<owl:DatatypeProperty rdf:about="http://purls.helmholtz-metadaten.de/cmso/hasSymbol">
<rdfs:domain rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:label>has symbol</rdfs:label>
<skos:definition>A data property linking an entity with its symbol.</skos:definition>
</owl:DatatypeProperty>
Expand Down Expand Up @@ -781,7 +781,7 @@
<rdfs:label>Amorphous Material</rdfs:label>
<skos:altLabel>Amorphous Solid</skos:altLabel>
<skos:altLabel>Non-crystalline Solid</skos:altLabel>
<skos:definition>An amorphous material or solid is a material which has no defined long-range periodicity.</skos:definition>
<skos:definition>An amorphous material or solid is a material which has no defined long-range order.</skos:definition>
</owl:Class>


Expand Down
37 changes: 27 additions & 10 deletions pyscal_rdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self, graph_file=None,
if ontology is None:
ontology = read_ontology()
self.ontology = ontology
self.terms = self.ontology.terms
self._atom_ids = None
self.store = store

Expand Down Expand Up @@ -291,7 +292,7 @@ def add_chemical_composition(self):
element = URIRef(element_indetifiers[e])
self.add((chemical_species, CMSO.hasElement, element))
self.add((element, RDF.type, CMSO.Element))
self.add((element, CMSO.hasSymbol, Literal(e, datatype=XSD.string)))
self.add((element, CMSO.hasChemicalSymbol, Literal(e, datatype=XSD.string)))
self.add((element, CMSO.hasElementRatio, Literal(r, datatype=XSD.float)))

def add_simulation_cell(self):
Expand Down Expand Up @@ -404,10 +405,12 @@ def add_space_group(self):
Returns
-------
"""
self.add((self.crystal_structure, CMSO.hasSpaceGroupSymbol,
space_group = URIRef(f'{self._name}_SpaceGroup')
self.add((self.crystal_structure, CMSO.hasSpaceGroup, space_group))
self.add((space_group, CMSO.hasSpaceGroupSymbol,
Literal(self.system.schema.material.crystal_structure.spacegroup_symbol(),
datatype=XSD.string)))
self.add((self.crystal_structure, CMSO.hasSpaceGroupNumber,
self.add((space_group, CMSO.hasSpaceGroupNumber,
Literal(self.system.schema.material.crystal_structure.spacegroup_number(),
datatype=XSD.integer)))

Expand Down Expand Up @@ -898,13 +901,27 @@ def query(self, inquery):
raise ValueError("SPARQL query returned None")

def auto_query(self, source, destination,
condition=None, return_query=False, enforce_types=True):
query = self.ontology.create_query(source, destination,
condition=condition, enforce_types=enforce_types)
if return_query:
return query
return self.query(query)

condition=None,
return_query=False,
enforce_types=None):

if enforce_types is None:
for val in [True, False]:
query = self.ontology.create_query(source, destination,
condition=condition, enforce_types=val)
if return_query:
return query
res = self.query(query)
if len(res) != 0:
return res
else:
query = self.ontology.create_query(source, destination,
condition=condition, enforce_types=val)
if return_query:
return query
res = self.query(query)

return res

#################################
# Methods to interact with sample
Expand Down
1 change: 1 addition & 0 deletions pyscal_rdf/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def create_query(self, source, destinations, condition=None, enforce_types=True)
#now add corresponding triples
for destination in destination_names:
for triple in all_triplets[destination]:
print(triple)
query.append(" ?%s %s ?%s ."%(self.strip_name(triple[0]),
triple[1],
self.strip_name(triple[2])))
Expand Down
5 changes: 5 additions & 0 deletions pyscal_rdf/network/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def read_ontology():
combo.add_term('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'object_property', delimiter='#', namespace='rdf')

#add paths

#General fixes
combo.add_path(('cmso:CrystalStructure', 'cmso:hasAltName', 'string'))
combo.add_path(('cmso:ChemicalElement', 'cmso:hasSymbol', 'string'))

#interontology paths
combo.add_path(('cmso:Material', 'cmso:hasDefect', 'pldo:PlanarDefect'))
combo.add_path(('cmso:Material', 'cmso:hasDefect', 'podo:Vacancy'))
combo.add_path(('cmso:SimulationCell', 'podo:hasVacancyConcentration', 'float'))
Expand Down
22 changes: 22 additions & 0 deletions pyscal_rdf/network/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from pyscal_rdf.network.term import OntoTerm, strip_name
from pyscal_rdf.network.patch import patch_terms

from owlready2 import get_ontology
import owlready2

Expand Down Expand Up @@ -98,6 +100,22 @@ def _parse_data_property(self):
rn = [r.__name__ for r in rn[0].Classes if r is not None]
except:
rn = [r.__name__ for r in rn if r is not None]


#Subproperties
#Commented out for now
#subprops = self.tree.search(subproperty_of=getattr(self.tree, c.name))
#for subprop in subprops:
# if subprop.iri != iri:
# #print(subprop.iri)
# pass

#PATCH
#Here: we patch specific items specifically for pyscal rdf
rn = patch_terms(iri, rn)

#print(iri, rn)
#print(iri, dm)
term = OntoTerm(iri, delimiter=self.delimiter)
term.domain = dm
term.range = rn
Expand All @@ -107,6 +125,10 @@ def _parse_data_property(self):
for d in dm:
if d!='07:owl#Thing':
self.attributes['class'][d].is_range_of.append(term.name)


#subproperties should be treated the same


def _parse_object_property(self):
for c in self.tree.object_properties():
Expand Down
28 changes: 28 additions & 0 deletions pyscal_rdf/network/patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
These are patches specifically designed for pyscal-rdf.

These may or may not be implemented in the ontology. As it is implemented; it can be removed
from the patches
"""

import os

def patch_terms(iri, rn):
"""
Remove functions as patching is done
"""
#Term: hasSymbol
#Ontology: CMSO
#Reason: Range is not specified in the owl file.
#This prevents owlready2 from reading in this property correctly.
if iri == 'http://purls.helmholtz-metadaten.de/cmso/hasSymbol':
rn = ['str']
#Term: hasValue
#Ontology: CMSO
#Reason: Range is Literal(); however here we use this for number values, hence we can fix this.
#See fn: `add_calculated_property`
elif iri == 'http://purls.helmholtz-metadaten.de/cmso/hasValue':
rn = ['float']

return rn

1 change: 1 addition & 0 deletions pyscal_rdf/network/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, uri,
#identifier
self.node_id = node_id
self.subclasses = []
self.subproperties = []
self.delimiter = delimiter
self.is_domain_of = []
self.is_range_of = []
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='pyscal_rdf',
version='0.1.5',
version='0.1.6',
author='Abril Azocar Guzman, Sarath Menon',
author_email='[email protected]',
description='Ontology based structural manipulation and quering',
Expand Down
Loading