The python package "linked-data-python" can rewrite a .ldpy file into an equivalent python code.
Reason this release was yanked:
broken dependency to antlr4
Project description
Linked-Data Python
The Linked-Data Python package can rewrite a .ldpy file into an equivalent python code.
Installation
You can install the Linked-Data Python
pip install linked-data-python
The Linked-Data Python syntax
The extension "linked-data-python" for Visual Studio Code enables the syntax highlighting for Linked-Data Python source files (extensions .ldpy).
The Linked-Data Python grammar only uses grammar rules supported by MicroPython 1.18, and adds support for Linked Data languages primitives and constructs:
- prefix declaration statements:
@prefix ex: <http://example.org/> .
- base declaration statements:
@base <http://example.org/> .
- IRIs: `http://example.org/
- Prefixed names:
ex:Person
- RDF literals:
"hello"^^xsd:string
,f"hello {world}"@en
- RDF graphs:
g{ ex:Person a owl:Class ; rdfs:label "Person"@en }
Furthermore, it allows:
- formatted IRIs:
f<http://example/org/{ id }/>
- RDF expression variables in RDF graphs:
g{ ex:Person ex:age ?{ age } }
Example programs are available in the examples
folder of the source code repository.
How to use
The Linked-Data Python package is a command line application, name ldpy
. It can also be run as python -m ldpy
.
$ python -m ldpy -h
usage: __main__.py [-h] [-l] [-p] [-s] [-x] file
Rewrite a .ldpy file into an equivalent python code.
positional arguments:
file the file to rewrite
optional arguments:
-h, --help show this help message and exit
-l, --debug-lexer print the lexer output
-p, --debug-parser print the parser output
-s, --silent do not display the output code
-x, --execute execute the output code
You can also run a transformation in your own Python code, by importing from the ldpy
package:
from ldpy import *
input_stream = FileStream(file) # or = InputStream(string)
lexer = LDPythonLexer(input_stream)
stream = MultiChannelTokenStream(lexer)
parser = LDPythonParser(stream)
tree = parser.file_input()
if parser.getNumberOfSyntaxErrors() != 0:
raise Exception("Exception while parsing the input")
output = IndentedStringWriter()
visitor = LDPythonRewriter(output)
visitor.visit(tree)
print("\noutput:\n" + output.getvalue())
Run from the source code
1. Dependencies
# cd ldpy
pip install -r requirements.txt
2. Generate the parser
Generate the SWPythonLexer
, SWPythonParser
, and SWPythonVisitor
using ANTLR4:
# cd ldpy
antlr4 -o ldpy/rewriter/antlr -package ldpy.rewriter.antlr -Xexact-output-dir -Dlanguage=Python3 -visitor -no-listener grammars/LDPython.g4
Release Notes
0.0.1
Initial release of the Linked-Data Python package
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for linked_data_python-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38720bfcfbe10bde98a96af1dbd74df3c32e0ac1876803932109d4b056dfe125 |
|
MD5 | 13528262884a2384f9ca04ce1f6c2602 |
|
BLAKE2b-256 | 0e6f5c1336cb52257f72afc8a34cd904da46f0c4a213929e4d3f82dad2812e27 |