Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d95bf6a

Browse files
committed
Repaired error in the parsing of case insensitive IRI, BNODE, etc
1 parent 93d2de3 commit d95bf6a

File tree

7 files changed

+136
-83
lines changed

7 files changed

+136
-83
lines changed

python/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# This module contains the Python bindings of rudof which are called pyrudof
1+
# Rudof Python bindings
2+
3+
The Python bindings for [rudof](https://rudof-project.github.io/) are called `pyrudof`. They are available at [pypi](https://pypi.org/project/pyrudof/).
4+
5+
For more information, you can access the [readthedocs documentation](https://pyrudof.readthedocs.io/en/latest/).
26

37
After compiling and installing this module, a Python library called `pyrudof` should be available.
48

python/examples/compare_schemas.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pyrudof import Rudof, RudofConfig, ShExFormatter
2+
3+
rudof = Rudof(RudofConfig())
4+
dctap_str = """shapeId,propertyId,Mandatory,Repeatable,valueDatatype,valueShape
5+
Person,name,true,false,xsd:string,
6+
,birthdate,false,false,xsd:date,
7+
,enrolledIn,false,true,,Course
8+
Course,name,true,false,xsd:string,
9+
,student,false,true,,Person
10+
"""
11+
rudof.read_dctap_str(dctap_str)
12+
13+
dctap = rudof.get_dctap()
14+
print(f"DCTAP\n{dctap}")
15+
16+
rudof.dctap2shex()
17+
result = rudof.serialize_shex(ShExFormatter())
18+
print(f"DCTAP converted to ShEx\n{result}")

python/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
use pyo3::prelude::*;
44
mod pyrudof_lib;
55

6-
use crate::pyrudof_lib::*;
6+
pub use crate::pyrudof_lib::*;
77

88
// Rudof Python bindings
99
#[pymodule]
1010
pub mod pyrudof {
1111
use super::*;
1212

1313
#[pymodule_export]
14-
use super::{
14+
pub use super::{
1515
PyCompareSchemaFormat, PyCompareSchemaMode, PyDCTAP, PyDCTapFormat, PyQuerySolution,
1616
PyQuerySolutions, PyRDFFormat, PyReaderMode, PyRudof, PyRudofConfig, PyRudofError,
1717
PyServiceDescriptionFormat, PyShExFormat, PyShExFormatter, PyShaclFormat,

python/src/pyrudof_lib.rs

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ impl PyRudof {
118118
shex_schema.map(|s| PyShExSchema { inner: s.clone() })
119119
}
120120

121-
/// Obtains the current ShEx Schema
121+
/// Compares two schemas provided as strings
122+
/// Parameters: schema1, schema2: Strings containing the schemas to compare
123+
/// mode1, mode2: Mode of the schemas, e.g. shex
124+
/// format1, format2: Format of the schemas, e.g. shexc, turtle
125+
/// label1, label2: Optional labels of the shapes to compare
126+
/// base1, base2: Optional base IRIs to resolve relative IRIs in the schemas
122127
#[pyo3(signature = (schema1, schema2, mode1, mode2, format1, format2, label1, label2, base1, base2))]
123128
pub fn compare_schemas_str(
124129
&mut self,
@@ -761,18 +766,21 @@ pub enum PyUmlGenerationMode {
761766
PyNeighs { node: String },
762767
}
763768

769+
/// UML Generation Mode
764770
#[pymethods]
765771
impl PyUmlGenerationMode {
766772
#[new]
767773
pub fn __init__(py: Python<'_>) -> Self {
768774
py.detach(|| PyUmlGenerationMode::PyAllNodes {})
769775
}
770776

777+
/// Show all nodes
771778
#[staticmethod]
772779
pub fn all() -> Self {
773780
PyUmlGenerationMode::PyAllNodes {}
774781
}
775782

783+
/// Show only the neighbours of a given node
776784
#[staticmethod]
777785
pub fn neighs(node: &str) -> Self {
778786
PyUmlGenerationMode::PyNeighs {
@@ -804,13 +812,24 @@ pub struct PyShExSchema {
804812
inner: ShExSchema,
805813
}
806814

815+
/// ShEx Schema representation
807816
#[pymethods]
808817
impl PyShExSchema {
809818
pub fn __repr__(&self) -> String {
810819
format!("{}", self.inner)
811820
}
821+
822+
/* /// Converts the schema to JSON
823+
pub fn as_json(&self) -> PyResult<String> {
824+
let str = self
825+
.inner
826+
.as_json()
827+
.map_err(|e| PyRudofError::str(e.to_string()))?;
828+
Ok(str)
829+
} */
812830
}
813831

832+
/// DCTAP representation
814833
#[pyclass(name = "DCTAP")]
815834
pub struct PyDCTAP {
816835
inner: DCTAP,
@@ -827,6 +846,8 @@ impl PyDCTAP {
827846
}
828847
}
829848

849+
/// ShapeMap used for querying and validation
850+
/// It can be converted to JSON
830851
#[pyclass(name = "QueryShapeMap")]
831852
pub struct PyQueryShapeMap {
832853
inner: QueryShapeMap,
@@ -837,21 +858,31 @@ impl PyQueryShapeMap {
837858
fn __repr__(&self) -> String {
838859
format!("{}", self.inner)
839860
}
861+
862+
/*pub fn as_json(&self) -> PyResult<String> {
863+
let str = self
864+
.inner
865+
.as_json()
866+
.map_err(|e| PyRudofError::str(e.to_string()))?;
867+
Ok(str)
868+
}*/
840869
}
841870

842871
/// Shapes Comparator result
872+
/// It contains the differences between two schemas
873+
/// It can be converted to JSON
843874
#[pyclass(name = "ShaCo")]
844875
pub struct PyShaCo {
845876
inner: ShaCo,
846877
}
847878

848879
#[pymethods]
849880
impl PyShaCo {
850-
fn __repr__(&self) -> String {
881+
pub fn __repr__(&self) -> String {
851882
format!("{}", self.inner)
852883
}
853884

854-
fn as_json(&self) -> PyResult<String> {
885+
pub fn as_json(&self) -> PyResult<String> {
855886
let str = self
856887
.inner
857888
.as_json()
@@ -868,9 +899,27 @@ pub struct PyCompareSchemaFormat {
868899

869900
#[pymethods]
870901
impl PyCompareSchemaFormat {
871-
fn __repr__(&self) -> String {
902+
pub fn __repr__(&self) -> String {
872903
format!("{}", self.inner)
873904
}
905+
906+
pub fn __str__(&self) -> String {
907+
format!("{}", self.inner)
908+
}
909+
910+
#[staticmethod]
911+
pub fn shexc() -> Self {
912+
Self {
913+
inner: CompareSchemaFormat::ShExC,
914+
}
915+
}
916+
917+
#[staticmethod]
918+
pub fn turtle() -> Self {
919+
Self {
920+
inner: CompareSchemaFormat::Turtle,
921+
}
922+
}
874923
}
875924

876925
/// Mode of schema to compare, e.g. shex, ...
@@ -881,9 +930,20 @@ pub struct PyCompareSchemaMode {
881930

882931
#[pymethods]
883932
impl PyCompareSchemaMode {
884-
fn __repr__(&self) -> String {
933+
pub fn __repr__(&self) -> String {
934+
format!("{}", self.inner)
935+
}
936+
937+
pub fn __str__(&self) -> String {
885938
format!("{}", self.inner)
886939
}
940+
941+
#[staticmethod]
942+
pub fn shex() -> Self {
943+
Self {
944+
inner: CompareSchemaMode::ShEx,
945+
}
946+
}
887947
}
888948

889949
#[pyclass(name = "ShaclSchema")]

0 commit comments

Comments
 (0)