Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiskeely committed Dec 1, 2019
1 parent 3fb4f21 commit 877a592
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 28 deletions.
74 changes: 59 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,66 @@
# shaclgen
shaclgen generates shacl templates based on the properties and classes present in a graph. This module uses the rdflib library for working with rdf.
SHACLGEN
========

Shaclgen takes either a data graph(s) or schema(s) as input and
generates a basic shape file based on the classes and properties
present.

**Shape files from data graphs:** By default, the input graph is
processed as a data graph (instance triples). Three formats are possible
for data graphs: simple, nested, and extended.

### From the command line:
```
$ shaclgen [uri to data] [serialization]
```
- Simple: Each class and property generate individual Node- and
PropertyShapes.
- Nested: Property shapes will be nested in nodeshapes iif they occur
with one class.
- Extended: Expands nested shapes to create individual property shapes
for each property, in addition to nesting them when appropriate.

Supported serializations include:
- `ttl` for turtle
- `xml` for rdf/xml
- `nt` for ntriples
**Shape files from ontologies:** If the input is a schema or ontology,
shaclgen generates a nested shape file: properties with rdfs:domain
defined in the ontology will be nested within the appropriate NodeShape.
rdfs:range definitions for XML and rdfs datatypes are included.

example:
```
$shaclgen https://www.lib.washington.edu/static/public/cams/data/datasets/uwSemWebParts/aggregation-1-0-0.ttl ttl
```
This project is still in development. Comments, questions, and issues are welcome!
Added support for OWL constructions is planned.

* * * * *

Installation
------------

Using pip: :

pip install shaclgen

From source:

<https://github.com/alexiskeely/shaclgen>

Command line use:
-----------------

$ shaclgen graph [optional arguments]

Example usage: :

$ shaclgen https://www.lib.washington.edu/static/public/cams/data/datasets/uwSemWebParts/webResource-1-0-0.nt

Command line arguments: :

positional arguments:
graph The data graph(s).

optional arguments:
-h, --help show this help message and exit
-nf, --nested generates a nested shape file
-ef, --extended generates an expanded shape file
-o, --ontology input file(s) or URL(s) is a schema or ontology
-s SERIALIZATION, --serialization SERIALIZATION
result graph serialization, default is turtle

* * * * *

This project is still in development. Comments, questions, and issues
are welcome!

Contact alexiskm at uw dot edu.
26 changes: 13 additions & 13 deletions shaclgen/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,19 @@ def gen_graph(self, serial='turtle'):
ng.add((blank, SH.datatype, rang))
else:
ng.add((blank, SH['class'], rang ))
for r in self.REST.keys():
if self.REST[r]['onProp'] == p and self.REST[r]['onClass'] == self.PROPS[p]['domain']:
if self.REST[r]['type'] in (OWL.cardinality):
ng.add((blank, SH.minCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
ng.add((blank, SH.maxCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
elif self.REST[r]['type'] in (OWL.minCardinality):
ng.add((blank, SH.minCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
elif self.REST[r]['type'] in (OWL.maxCardinality):
ng.add((blank, SH.maxCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
else:
pass
else:
pass
# for r in self.REST.keys():
# if self.REST[r]['onProp'] == p and self.REST[r]['onClass'] == self.PROPS[p]['domain']:
# if self.REST[r]['type'] in (OWL.cardinality):
# ng.add((blank, SH.minCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
# ng.add((blank, SH.maxCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
# elif self.REST[r]['type'] in (OWL.minCardinality):
# ng.add((blank, SH.minCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
# elif self.REST[r]['type'] in (OWL.maxCardinality):
# ng.add((blank, SH.maxCount, Literal(self.REST[r]['value'], datatype=XSD.integer)))
# else:
# pass
# else:
# pass
else:
label = self.PROPS[p]['label']
ng.add((EX[label], RDF.type, SH.NodeShape))
Expand Down

0 comments on commit 877a592

Please sign in to comment.