Skip to content

Commit

Permalink
doc (miscellaneous.md): add example for sparql query (from unittest)
Browse files Browse the repository at this point in the history
# Last 3 commits:

# f96456a I42 update 
# 91ae143 abstract pow / neg class 
# dd995a5 abstract add / mul class
  • Loading branch information
cknoll committed Jan 20, 2025
1 parent f96456a commit c894eb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions docs/source/howto/miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,27 @@ to type. Solutions:
- The extension uses the entries in this file to offer auto-complete suggestions when the `erk-fzf.search` command is triggered (either via the VS code command pallette or via a manually assigned keyboard shortcut (recommended, see [README.md](https://github.com/ackrep-org/irk-fzf/blob/main/README.md)).
- The command `erk-fzf.search` performs a fuzzy search using the string left of the cursor (and then the user input).
It displays fuzzy-matching lines from `.ac_candidates.txt`. It searches short_keys, labels and descriptions.


## How to perform a SPARQL query


Example from `test_core.py:Test_04_Core.test_c020__sparql_query2`

```python

import pyirk as p
p.ds.rdfgraph = p.rdfstack.create_rdf_triples()

qsrc = f"""
PREFIX : <{p.rdfstack.IRK_URI}>
PREFIX ct: <{mod1.__URI__}#>
SELECT ?s ?o
WHERE {{
?s :R16 ct:I7864.
}}
"""
res = p.ds.rdfgraph.query(qsrc)
res2 = p.aux.apply_func_to_table_cells(p.rdfstack.convert_from_rdf_to_pyirk, res)

```
8 changes: 4 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1900,13 +1900,13 @@ def test_b02m__multilingual_relations2(self):
self.assertEqual(I1001.R77__has_alternative_label, expected_result)


class Test_Z_Core(HousekeeperMixin, unittest.TestCase):
class Test_04_Core(HousekeeperMixin, unittest.TestCase):
"""
Collection of test that should be executed last (because they seem to influence other tests).
This is achieved by putting "ZZ" in the name (assuming that test classes are executed in alphabetical order).
"""

def test_sparql_query(self):
def test_c010_sparql_query(self):
# This test seems somehow to influence later tests
mod1 = p.irkloader.load_mod_from_path(TEST_DATA_PATH2, TEST_MOD_NAME)
p.ds.rdfgraph = p.rdfstack.create_rdf_triples()
Expand All @@ -1921,7 +1921,7 @@ def test_sparql_query(self):
]
self.assertEqual(res2[:2], expected_result)

def test_c01__sparql_query2(self):
def test_c020__sparql_query2(self):
# TODO: replace by Model entity once it exists
mod1 = p.irkloader.load_mod_from_path(TEST_DATA_PATH2, TEST_MOD_NAME)

Expand Down Expand Up @@ -1951,7 +1951,7 @@ def test_c01__sparql_query2(self):
]
self.assertEqual(res2, expected_result)

def test_c02__sparql_zz_preprocessing(self):
def test_c030__sparql_zz_preprocessing(self):
mod1 = p.irkloader.load_mod_from_path(TEST_DATA_PATH2, TEST_MOD_NAME)

with p.uri_context(uri=TEST_BASE_URI):
Expand Down

0 comments on commit c894eb6

Please sign in to comment.