The python package "linked-data-python" can execute .ldpy files and run an interactive ldpy console.
Project description
Linked-Data Python
The Linked-Data Python package allow to run .ldpy scripts, run a ldpy interactive console, and import .ldpy library modules.
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 }/>
- formatted nodes in RDF graphs:
f{ ex:Person ex:age ?{ age } }
Example programs are available in the examples
folder of the source code repository.
How to use
In the command line
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] [-v] [-l] [-p] [-s] [-i] [-m MODULE | source]
ldpy extends the Python syntax with primitives from the Semantic Web such as namespaces, RDF terms, and RDF graphs.
If no source is given, ldpy will start an interactive console.
positional arguments:
source Program read from script file. The file extension may be .ldpy or .py.
optional arguments:
-h, --help show this help message and exit
-v, --version only displays the current version.
-l, --debug-lexer print the lexer output
-p, --debug-parser print the parser output
-s, --show_changes shows the transformed code before it is executed.
-i starts the interactive console after executing a source
-m MODULE, --module MODULE
Run library module as a script. The module may be a .ldpy or a .py file.
As a module
import ldpy
ldpy.config.debug_ldpy = True # print transformed source
ldpy.config.debug_lexer = False # print tokens
ldpy.config.debug_parser = False # print syntax tree
ldpy.transform_source(source) # transform a Linked-Data Python source into a Python source
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
All notable changes to the "linked-data-python" are documented below.
[0.0.3] - 2023-02-24
- use
ideas
import hooks to enable using.ldpy
files from import statements - added interactive ldpy console
- added line mapping to point to the right line in the
.ldpy
file on error - corrected small bugs in the parser
[0.0.2] - 2022-04-30
- corrected many small bugs
- added many examples
- add
-d
functionality
[0.0.1] - 2022-04-29
- Initial release
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
File details
Details for the file linked-data-python-0.0.4.tar.gz
.
File metadata
- Download URL: linked-data-python-0.0.4.tar.gz
- Upload date:
- Size: 79.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c0569ecc9ec93436d4af503bf8af297a1817df5fab9916aaee29c803eb509bb |
|
MD5 | 59a7202fadcb185f032d1f170ed4e8bf |
|
BLAKE2b-256 | 45843988aba8816838ee309f28b10f7cf34762f9a4dc1d8501060da36a4cf6ed |
File details
Details for the file linked_data_python-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: linked_data_python-0.0.4-py3-none-any.whl
- Upload date:
- Size: 72.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0990d9a7b7bda969138562bcf8ec358fce43aaf6b53e727b0c6a31dcf8042f46 |
|
MD5 | c628a65e9deed65e9e60a54a2789cdf8 |
|
BLAKE2b-256 | 9639c493f2efe63a01b777cff60299172788ff7f1805b2b54abf5312a2bf471b |