Skip to content

Commit 4f73eca

Browse files
AnnaBobashevaj-l-s
andauthored
Downgrade version to Beta 0.1.4 with updates (#13)
* typo * maven-artifact python package not necessary * call CoreseInfo.getVersion() instead of returning a static sting * Feature/add example notebook (#11) * updated example dir and notebook * Update example1.ipynb * Changed GoogleColab link * Updated README files, dependencies, and downgraded version (#12) * Update INSTALL.md --------- Co-authored-by: Jean Luc Szpyrka <Jean-Luc.Szpyrka@inria.fr>
1 parent 9adb0b2 commit 4f73eca

File tree

13 files changed

+1706
-538
lines changed

13 files changed

+1706
-538
lines changed

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,20 @@ cython_debug/
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
.idea/
163-
.gradle
164-
build
165-
log
166163

167164
# VSCode
168165
.vscode/
169166

170-
171167
# garbage
172168
\#*
173169
.\#*
174170

175171
# backup files
176172
resources/
177-
*.bak
173+
*.bak
174+
175+
# Java class files
176+
.gradle/
177+
build/
178+
log/
179+
bin/

INSTALL.md

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,180 @@
1-
# how to build/test/install pycorese java gateway and python wrapper from sources
1+
# Development Installation
22

3-
## build/install the python package
3+
This document describes how to install the development environment for the **pycorese** package.
44

5-
### prerequesite
5+
**pycorese** is a Python wrapper for the [Corese-core](https://github.com/corese-stack/corese-core) Java library. To build and use this package, you need to have Java installed on your system.
66

7+
**pycorese** provides two options for running the Corese Java code using the following Python packages to access Java objects:
8+
9+
* [Py4J](https://www.py4j.org/)
10+
* [JPype](https://jpype.readthedocs.io/en/latest/)
11+
12+
That's the reason the installation process is a bit more complex than for a standard Python package.
13+
14+
## Clone the GitHub repository
15+
16+
```bash
17+
git clone https://github.com/corese-stack/corese-python.git
18+
cd corese-python
719
```
8-
pip install --upgrade pip setuptools wheel build
20+
21+
22+
## Python build environment
23+
24+
You can use the provided [conda](https://docs.conda.io/en/latest/) environment file to create a virtual environment with the necessary dependencies.
25+
26+
```bash
27+
conda env update -f pkg/env/corese-python.yaml
28+
conda activate corese-python
929
```
30+
Or install the dependencies manually:
31+
32+
* project dependencies:
33+
```bash
34+
pip install py4j jpype1 pandas
35+
```
36+
* build dependencies:
37+
```bash
38+
pip install --upgrade pip setuptools wheel build
39+
```
40+
* test dependencies:
41+
```bash
42+
pip install pytest pytest-cov
43+
```
44+
* documentation dependencies:
45+
```bash
46+
pip install sphinx pydata_sphinx_theme
47+
```
48+
49+
<!-- TODO: Add other documentation dependencies install support-->
50+
<!-- TODO: Add conda install support-->
51+
52+
## Java build environment
53+
54+
To build the package Java Development Kit (JDK) version 11 or higher and the [Gradle](https://docs.gradle.org/current/userguide/userguide.html) build tool are required.
55+
56+
If Java is not installed, visit the [official website](https://www.java.com/en/download/help/download_options.html) for installation instructions.
57+
58+
Gradle can be installed as an extension to your IDE or as a standalone tool.
59+
60+
* Gradle extension for VSCode is available from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-gradle)
1061

11-
### clean all (not necessary if your just downloaded the sources)
62+
* To install Gradle as a standalone tool, follow the instructions on the [official website](https://gradle.org/install/).
63+
64+
65+
## Building the package
66+
67+
Clean all the build directories (not necessary if you just downloaded the source code):
1268

1369
```
14-
rm -fr dist build resources
70+
rm -fr dist build resources src/pycorese.egg-info
1571
```
1672

17-
### build the package
73+
Build the package:
1874

1975
```
2076
python -m build
2177
```
2278

23-
which build the packages into `./dist`
79+
This command builds the packages into `./dist` directory. Note that the custom `sdist` command is implemented in [setup.py](./setup.py).
2480

25-
Remark:
26-
- do not run `python setup.py` which will not build the full package
27-
- the described install process will:
81+
The custom `sdist` command adds the following steps:
2882

29-
1/ compile the `corese-python-4.x.y-jar-with-dependencies.jar` file
30-
2/ download the `corese-core-4.x.y-jar-with-dependencies.jar` file from maven
83+
* compiling the `corese-python-x.y.z-jar-with-dependencies.jar` file using the Gradle build tool. This jar file is required to run Corese using the `Py4J` bridge.
84+
* downloading the `corese-core-x.y.z-jar-with-dependencies.jar` file from the Maven repository. This jar file is required to run Corese using the `JPype` bridge.
85+
* copying the jar files to the `./resources` directory.
3186

32-
- these two files are necessary to run the wrappers and are part of the distribution
87+
> [!NOTE]
88+
> - do not run `python setup.py` that will not build the full package.
89+
> - the versions of `pycorese` and Java libraries are maintained separately.
90+
> - `corese-python` version should be the same as `corese-core` it depends on, for simplicity reasons.
91+
> - the commands for the first two steps are provided in the [Obtaining Java libraries manually](#obtain-java-libraries-manually) section.
3392

34-
### test
93+
## Testing the package
3594

36-
From the top directory, or in the `tests` sub-directory
37-
38-
```
39-
pip install pytest
40-
```
95+
From the top directory, or in the `./tests` sub-directory run the command:
4196

4297
```
4398
pytest -v
4499
```
45100

46-
If a specific test fails, you can have more information, using:
47-
(you need to know the filename, test class name, test name)
101+
If a specific test fails, you can have more information, using the following command:
48102

49-
eg:
50103
```
51104
pytest tests/test_api.py::Test_api::test_bad_bridge
52105
```
53106

54-
### code coverage
55-
56-
Install the coverage package:
57-
58-
```
59-
pip install pytest-cov
60-
```
107+
> [!NOTE]
108+
> - substitute the filename, test class name, and test name with your specific test.
61109

62-
And run the test coverage:
110+
Run the test coverage:
63111

64112
```
65113
pytest --cov
66114
```
67115

68-
If you prefer a browsable coverage report:
116+
For the HTML coverage report, run the following commands:
69117

70118
```
71119
pytest --cov --cov-report=html
72120
open htmlcov/index.html
73121
```
74122

75123

76-
### install the locally built package
124+
## Installing the locally built package
77125

78126
```
79-
pip install dist/pycorese-1.0.1-py3-none-any.whl
127+
pip install dist/pycorese-0.1.1-py3-none-any.whl
80128
```
81129

82130
or
83131
```
84-
pip install dist/pycorese-1.0.1.tar.gz
132+
pip install dist/pycorese-0.1.1.tar.gz
85133
```
86134

87-
- verify your installation
135+
## Verifying the installation
88136

89137
```
90138
$ pip list | grep corese
91-
pycorese 1.0.1
139+
pycorese 0.1.1
92140
93141
$ python -c 'import pycorese'
94142
```
143+
> [!NOTE]
144+
> - change the version number accordingly.
95145

96-
## Appendix 1: run local python example
97146

98-
### Conda environment
147+
## Run a simple example
99148

100-
If necessary, we provide a conda environment:
149+
Without installing the package you can run the following command (the default Java bridge is `py4j`):
101150

102-
```bash
103-
conda env update -f pkg/env/corese-python.yaml
104-
conda activate corese-python
105151
```
106-
107-
This makes available the python libraries: `pandas`, `py4j`, `jpype1`
108-
109-
### run a simple example using py4j bridge (without installing)
110-
111-
```
112-
./python_examples/simple_query.py -j $PWD/build/libs/corese-python-4.6.0-jar-with-dependencies.jar
152+
./examples/simple_query.py -j $PWD/build/libs/corese-python-4.6.0-jar-with-dependencies.jar
113153
```
114154

115-
Remark: to build this jar file, you must follow the Appendix 2 instructions
116-
117-
### experimental: run a simple example using jpype bridge (without installing)
118-
119-
We focus the development on the py4j wrapping. The (still provided) jpype interface
120-
may still work (without garanty):
155+
or change the bridge to `jpype`:
121156

122157
```
123-
./python_examples/simple_query.py -b jpype -j /somewhere/corese-core-4.6.0-jar-with-dependencies.jar
158+
./examples/simple_query.py -b jpype -j $PWD/build/libs/corese-core-4.6.0-jar-with-dependencies.jar
124159
```
125160

161+
<!-- **_NOTE:_** -->
162+
> [!NOTE]
163+
> - the jar files are obtained either by [building the package](#building-the-package) or [manually](#obtain-java-libraries-manually).
164+
> - the primary development focus is on using the `py4j` bridge.
126165

127-
## Appendix 2: java compilation description
128166

129-
Remark: all these commands are launched then building/installing using the previous described process
167+
## Obtain Java libraries manually
130168

131-
### build jar file locally
169+
In case you want to build `corese-python-x.y.z-jar-with-dependencies.jar` Java library separately, use the following commands:
132170

133171
```
134-
./gradlew shadowJar
172+
gradlew shadowJar
135173
```
136174

137-
### download
175+
In case you want to download the `corese-core-x.y.z-jar-with-dependencies.jar` Java library separately, use the following commands:
138176

139177
```
140-
./gradlew downloadCoreseCore
178+
gradlew downloadCoreseCore
141179
```
180+
These tasks are defined in the [build.gradle.kts](./build.gradle.kts) file.

README.md

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,96 @@
1-
# pycorese
1+
<div align="center">
2+
<h2>pycorese</h2>
3+
</div>
24

3-
pycorese is a python wrapper to the corese "Software platform for the Semantic Web of Linked Data"
5+
<!-- Short description -->
6+
<p align="center">
7+
Python API for CORESE Semantic Web platform
8+
</p>
49

5-
## Easy installation
10+
<!-- Badges -->
11+
<p align="center">
12+
<img src="https://img.shields.io/pypi/pyversions/pycorese.svg" alt="Python Versions">
13+
<a href="https://pypi.org/project/pycorese/"><img src="https://img.shields.io/pypi/v/pycorese?color=informational" alt="PyPI version"></a>
14+
<a href="https://corese-stack.github.io/corese-python/"><img src="https://img.shields.io/badge/docs-GitHub%20Pages-blue" alt="Documentation"></a>
15+
<a href="https://codecov.io/gh/corese-stack/pycorese"><img src="https://codecov.io/gh/corese-stack/pycorese/branch/master/graph/badge.svg" alt="codecov"></a>
16+
<a href="https://opensource.org/licenses/LGPL-3.0"><img src="https://img.shields.io/badge/License-LGPL-yellow.svg" alt="License: LGPL"></a>
17+
</p>
618

7-
```
19+
<!-- Long description -->
20+
21+
[Corese](https://corese-stack.github.io/corese-core) is a software platform implementing and extending the standards of the Semantic Web. It allows to create, manipulate, parse, serialize, query, reason, and validate RDF data. Corese is based on the W3C standards RDF, RDFS, OWL 2, SPARQL and SHACL. Corese is implemented as a set of open-source Java libraries.
22+
23+
**pycorese** is a Python package that provides a simple way to integrate the [corese-core](https://github.com/corese-stack/corese-core) Java library into Python applications.
24+
25+
**pycorese** provides an intuitive API to interact with Corese's capabilities such as storage, SPARQL engine, RDFS and OWL reasoning, and SHACL validation.
26+
27+
**pycorese** unlocks the potential of Semantic Web stack for applications such as semantic data analysis, knowledge graph construction, and Machine Learning.
28+
29+
## Installation
30+
31+
**pycorese** can be easily installed via `pip`:
32+
33+
```bash
834
pip install pycorese
935
```
1036

11-
This will install the python wrappers and the corese jar files
37+
This process installs both the Python wrappers and the Corese Java libraries. To run the Java libraries, ensure that Java is installed on your system. A Java Runtime Environment (JRE) version 11 or higher is required. If Java is not installed, visit the [official website](https://www.java.com/en/download/help/download_options.html) for installation instructions.
38+
39+
<!-- TODO: conda installation-->
40+
41+
## Development installation
42+
43+
To install **pycorese** from the current [GitHub repository](https://github.com/corese-stack/corese-python) follow the instructions from [INSTALL.md](https://github.com/corese-stack/corese-python/blob/main/INSTALL.md).
44+
45+
## Usage
1246

13-
## Install from sources
47+
Here is a simple example of how to use **pycorese** to load and query RDF data:
1448

15-
Follow the instuctions from `INSTALL.md`
49+
```python
50+
from pycorese.api import CoreseAPI
51+
52+
corese = CoreseAPI()
53+
corese.loadCorese()
54+
55+
# Load RDF data
56+
data = """
57+
@prefix ex: <http://example.org/> .
58+
ex:John ex:hasFriend ex:Jane, ex:Jill.
59+
ex:Jane ex:age 25 .
60+
ex:Jill ex:age 40 .
61+
"""
62+
63+
graph = corese.loadRDF(data)
64+
65+
# Query the data to find out who is John's younger friend
66+
query = """
67+
PREFIX ex: <http://example.org/>
68+
SELECT ?friend ?age
69+
WHERE {
70+
?x ex:age ?ageX .
71+
?x ex:hasFriend ?friend .
72+
?friend ex:age ?age .
73+
FILTER (?ageX > ?age)
74+
}
75+
"""
76+
77+
results = corese.sparqlSelect(graph, query=query, return_dataframe=True)
78+
print(results)
79+
```
80+
Expected output:
81+
```
82+
friend age
83+
0 http://example.org/Jane 25
84+
```
85+
86+
See the [GitHub repository]((https://github.com/corese-stack/corese-python/examples)) for more examples.
1687

1788
## Documentation
1889

19-
Corese documentation: https://corese-stack.github.io/corese-core
20-
Corese python wrapper: https://corese-stack.github.io/corese-python
90+
- pycorese GitHub pages: https://corese-stack.github.io/corese-python
91+
- Corese GitHub pages: https://corese-stack.github.io/corese-core
92+
93+
94+
## Contributing
95+
96+
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please [open an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue) or [submit a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) on the [GitHub repository](https://github.com/corese-stack/corese-python).

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
0.1.4
File renamed without changes.

0 commit comments

Comments
 (0)