Skip to main content

Tool to generate shape expressions from CSV files

Project description

ShExStatements

ShExStatements allows the users to generate shape expressions from simple CSV statements or files. shexstatements can be used from the command line as well as from the web interface.

Quick start

Using pip

Set up a virtual environment and install shexstatements.

$ python3 -m venv .venv
$ source ./.venv/bin/activate
$ pip3 install shexstatements

Run the following command with an example CSV file. The file contains an example description of a language on Wikidata. This file uses comma as a delimiter to separate the values.

$ shexstatements.sh examples/language.csv

Build from source

Terminal

Clone the ShExStatements repository.

$ git clone https://github.com/johnsamuelwrites/ShExStatements.git 

Go to ShExStatements directory.

$ cd ShExStatements

Install modules required by ShExStatements (here: installing into a virtual environment).

$ python3 -m venv .venv
$ source ./.venv/bin/activate
$ pip3 install .

Run the following command with an example CSV file. The file contains an example description of a language on Wikidata. This file uses comma as a delimiter to separate the values.

$ ./shexstatements.sh examples/language.csv

CSV file can use delimiters like ;. Take for example, the following command works with a file using semi-colon as a delimiter.

$ ./shexstatements.sh examples/languagedelimsemicolon.csv --delim ";"

But sometimes, users may like to specify the header. In that case, they can make use of -s or --skipheader to tell the generator to skip the header (firsrt line of CSV).

$ ./shexstatements.sh --skipheader examples/languageheader.csv 

In all the above cases, the shape expression generated by ShExStatements will look like

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
start = @<language>
<language> {
  wdt:P31 [ wd:Q34770  ] ;# instance of a language
  wdt:P1705 LITERAL ;# native name
  wdt:P17 .+ ;# spoken in country
  wdt:P2989 .+ ;# grammatical cases
  wdt:P282 .+ ;# writing system
  wdt:P1098 .+ ;# speakers
  wdt:P1999 .* ;# UNESCO language status
  wdt:P2341 .+ ;# indigenous to
}

Use -j or --shexj to generate ShEx JSON Syntax (ShExJ) instead of default ShEx Compact syntax (ShExC).

$ ./shexstatements.sh --shexj examples/language.csv 

The output will be similiar to:

{
  "type": "Schema",
  "start": "language",
  "shapes": [
    {
      "type": "Shape",
      "id": "language",
      "expression": {

      }
    }
  ]
}

It's also possible to use application profiles of the following form

Entity_name,Property,Property_label,Mand,Repeat,Value,Value_type,Annotation

and Shape expressions can be generated using the following form

$ ./shexstatements.sh -ap --skipheader examples/languageap.csv 

Objectives

  • Easily generate shape expressions (ShEx) from CSV files
  • Simple syntax

Documentation and examples

A detailed documentation can be found here. with a number of example CSV files in the examples folder.

Test cases and coverage

All the test cases can be run in the following manner

$ python3 -m tests.tests

Code coverage report can also be generated by running the unit tests using the coverage tool.

$ coverage run --source=shexstatements -m unittest tests.test
$ coverage report -m

Web interface

shexstatements can also be accessed from a web interface. Clone the ShExStatements repository.

$ git clone https://github.com/johnsamuelwrites/ShExStatements.git 

Go to ShExStatements directory.

$ cd ShExStatements

Install modules required by ShExStatements (here: installing into a virtual environment).

$ python3 -m venv .venv
$ source ./.venv/bin/activate
$ pip3 install .

Now run the application.

$ ./shexstatements.sh -r 

Check the URL http://127.0.0.1:5000/

API

ShExStatements also has an API to generate ShEx from CSV and is described here.

Demonstration

Online demonstrations are also available:

Author

Acknowledgements

  • Wikidata Community

Archives and Releases

Licence

All code are released under GPLv3+ licence. The associated documentation and other content are released under CC-BY-SA.

Project details


Release history Release notifications | RSS feed

This version

0.7

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shexstatements-0.7.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

shexstatements-0.7-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file shexstatements-0.7.tar.gz.

File metadata

  • Download URL: shexstatements-0.7.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for shexstatements-0.7.tar.gz
Algorithm Hash digest
SHA256 61103e87a9802a8458ceea2e27c9e656029af42cde9ecd6254e27effa522b4d6
MD5 5ef3fe63ab4826e4d188f7bdf8ed3555
BLAKE2b-256 01c54722a4270e14638ce957d21ef21aeb3b7e65da660f30ea8d58288ce03f03

See more details on using hashes here.

File details

Details for the file shexstatements-0.7-py3-none-any.whl.

File metadata

  • Download URL: shexstatements-0.7-py3-none-any.whl
  • Upload date:
  • Size: 45.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for shexstatements-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ada1d90f3f2a0222ed1f84a82a4c614820469ee0eb68bbf70d4097aa3bec8f83
MD5 dd11b71e8922de0eed330efd2b5ca87a
BLAKE2b-256 215cb74dde10efc577d552d3488ef4e595c573becb464df821e0000d09d1c997

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page