Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Sep 13, 2023
2 parents b1b8ee1 + 0e09542 commit aa9a879
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 34 deletions.
30 changes: 14 additions & 16 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@ name: Python application

on:
push:
branches: [ "main", "dev" ]
branches: ["main", "dev"]
pull_request:
branches: [ "main", "dev" ]
branches: ["main", "dev"]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pytest
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ Changes to data are ignored for the purpose of this changelog.

## [Unreleased]

## [2.1.0] (2023-09-13)

### Added

- Support for deprecated terms:
- Any term having `owl:deprecated "true"^^xsd:boolean` will be present in the RDF API but omitted from the JSON API.
- `dcterms:replaces` is mirrored with `dcterms:isReplacedBy`

## [2.0.2] (2023-09-06)

### Added
Expand Down Expand Up @@ -85,7 +93,8 @@ Features:
- A build script that compiles multiple RDF/SKOS files (terms) to one (thesaurus).
- An HTTP server that exposes the data as RDF as well as more web-app-friendly JSON

[unreleased]: https://github.com/gu-gridh/queerlit-terms/compare/v2.0.2...HEAD
[unreleased]: https://github.com/gu-gridh/queerlit-terms/compare/v2.1.0...HEAD
[2.1.0]: https://github.com/gu-gridh/queerlit-terms/compare/v2.0.2...v2.1.0
[2.0.2]: https://github.com/gu-gridh/queerlit-terms/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/gu-gridh/queerlit-terms/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/gu-gridh/queerlit-terms/compare/v1.3.1...v2.0.0
Expand Down
7 changes: 5 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def replace_identifier(thesaurus: Thesaurus, old_id: str, new_id: str):
def check_changes(thesaurus: Thesaurus, thesaurus_prev: Thesaurus):
uris = thesaurus.refs()
uris_prev = thesaurus_prev.refs()

count_new = 0
count_changed = 0
count_removed = len(list(uri for uri in uris_prev if uri not in uris))
Expand Down Expand Up @@ -97,7 +97,10 @@ def is_infile(fn):
thesaurus = Thesaurus()

# Prepare parsing.
fns = [join(indir, fn) for indir in INDIR.split(':') for fn in os.listdir(indir) if is_infile(fn)]
indirs = INDIR.split(":")
for indir in indirs:
print(f'Reading files from {indir}')
fns = [join(indir, fn) for indir in indirs for fn in os.listdir(indir) if is_infile(fn)]
print(f'Parsing {len(fns)} files...')
skipped = []

Expand Down
6 changes: 2 additions & 4 deletions qlit.nt
Original file line number Diff line number Diff line change
Expand Up @@ -6780,7 +6780,7 @@
<https://queerlit.dh.gu.se/qlit/v1/nj44aa03> <http://www.w3.org/2004/02/skos/core#scopeNote> "Används för skildringar av homosexuella, bisexuella, transpersoner, queera och/eller intersexpersoner som beskrivs som icke-vita. Icke-vit förstås här som en rasifierande kategori som markerar personer med melaninrik hud eller andra karakteristika som rasifieras som icke-vita. Ämnesordet används för skildringar där identiteten som icke-vit är i fokus." .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://purl.org/dc/terms/identifier> "nj45ko84" .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://purl.org/dc/terms/issued> "2022-05-19T10:12:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://purl.org/dc/terms/modified> "2023-02-07T17:15:49"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://purl.org/dc/terms/modified> "2023-09-13T11:44:16"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#altLabel> "Bikvinnor" .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#altLabel> "Kvinnliga bisexuella" .
Expand All @@ -6793,7 +6793,6 @@
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#narrower> <https://queerlit.dh.gu.se/qlit/v1/cq47se04> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#narrower> <https://queerlit.dh.gu.se/qlit/v1/os42ys07> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#narrower> <https://queerlit.dh.gu.se/qlit/v1/pc36se94> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#narrower> <https://queerlit.dh.gu.se/qlit/v1/px69nf52> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#prefLabel> "Bisexuella kvinnor" .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#related> <https://queerlit.dh.gu.se/qlit/v1/dq66qs98> .
<https://queerlit.dh.gu.se/qlit/v1/nj45ko84> <http://www.w3.org/2004/02/skos/core#related> <https://queerlit.dh.gu.se/qlit/v1/px69nf52> .
Expand Down Expand Up @@ -8213,10 +8212,9 @@
<https://queerlit.dh.gu.se/qlit/v1/px55pp67> <http://www.w3.org/2004/02/skos/core#scopeNote> "Används för skildringar av HBTQI-personer som är anhängare av romersk-katolska kyrkan. Används även för skildringar av andra katolikers förhållningssätt till HBTQI." .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://purl.org/dc/terms/identifier> "px69nf52" .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://purl.org/dc/terms/issued> "2022-05-19T10:12:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://purl.org/dc/terms/modified> "2023-02-07T17:15:49"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://purl.org/dc/terms/modified> "2023-09-13T11:44:16"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://www.w3.org/2004/02/skos/core#broader> <https://queerlit.dh.gu.se/qlit/v1/cb49gf75> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://www.w3.org/2004/02/skos/core#broader> <https://queerlit.dh.gu.se/qlit/v1/nj45ko84> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://www.w3.org/2004/02/skos/core#inScheme> <https://queerlit.dh.gu.se/qlit/v1> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://www.w3.org/2004/02/skos/core#narrower> <https://queerlit.dh.gu.se/qlit/v1/qo25ba41> .
<https://queerlit.dh.gu.se/qlit/v1/px69nf52> <http://www.w3.org/2004/02/skos/core#prefLabel> "Kärlek mellan kvinnor" .
Expand Down
3 changes: 2 additions & 1 deletion qlit/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from os.path import basename
import re
from dotenv import load_dotenv
from rdflib import SKOS, URIRef, Literal
from rdflib import OWL, SKOS, URIRef, Literal
from .thesaurus import BASE, Termset, Thesaurus
from collections.abc import Generator

Expand Down Expand Up @@ -177,6 +177,7 @@ def add_hit(ref, score):

scored_hits = []
for ref, score in hits.items():
if self.th.value(ref, OWL.deprecated): continue
term = SimpleTerm.from_subject(self.t, ref)
term['score'] = score
scored_hits.append(term)
Expand Down
6 changes: 6 additions & 0 deletions qlit/skos.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ def skos_complete_graph(g: Thesaurus) -> None:
if not g.value(term, SKOS.broader):
g.set((term, SKOS.topConceptOf, g.scheme))
g.add((g.scheme, SKOS.hasTopConcept, term))

# replaces <-> isReplacedBy
for replaced in g[term:DCTERMS.replaces]:
g.add((replaced, DCTERMS.isReplacedBy, term))
for replacer in g[term:DCTERMS.isReplacedBy]:
g.add((replacer, DCTERMS.replaces, term))
29 changes: 22 additions & 7 deletions qlit/test_simple.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from rdflib import URIRef, RDF, SKOS
from .thesaurus import Thesaurus, Termset
from .simple import SimpleThesaurus, SimpleTerm, ref_to_name, name_to_ref, Tokenizer
from json import dumps

def test_tokenizer():
assert list(Tokenizer.split("foo bar")) == ["foo", "bar"]
Expand Down Expand Up @@ -46,12 +45,28 @@ def test_simple_term_from_termset():

terms = SimpleTerm.from_termset(termset)
assert len(terms) == 2
# Convert to json to compare objects
terms_json = dumps(terms, sort_keys=True)
term1 = SimpleTerm.from_subject(T, URIRef("https://queerlit.dh.gu.se/qlit/v1/ez04as46"))
term2 = SimpleTerm.from_subject(T, URIRef("https://queerlit.dh.gu.se/qlit/v1/lx88hn91"))
assert dumps(term1, sort_keys=True) in terms_json
assert dumps(term2, sort_keys=True) in terms_json
term1 = next(term for term in terms if term['name'] == 'ez04as46')
term2 = next(term for term in terms if term['name'] == 'lx88hn91')
assert term1['prefLabel'] == "Syskon"
assert term2['prefLabel'] == "Intersexseparatism"

sterm1 = SimpleTerm.from_subject(T, URIRef("https://queerlit.dh.gu.se/qlit/v1/ez04as46"))
sterm2 = SimpleTerm.from_subject(T, URIRef("https://queerlit.dh.gu.se/qlit/v1/lx88hn91"))
for term, sterm in ((term1, sterm1), (term2, sterm2)):

# Compare string values
for prop in ['name', 'uri', 'prefLabel', 'scopeNote']:
assert term[prop] == sterm[prop]

# Compare lists of strings
for prop in ['altLabels', 'hiddenLabels', 'broader', 'narrower', 'related']:
assert sorted(term[prop]) == sorted(sterm[prop])

# Compare lists of terms
for prop in ['exactMatch', 'closeMatch']:
def sort_by_uri(dicts):
return sorted(dicts, key=lambda t: t['uri'])
assert sort_by_uri(term[prop]) == sort_by_uri(sterm[prop])

def test_simple_term_get_labels():
term = SimpleTerm.from_subject(T, URIRef("https://queerlit.dh.gu.se/qlit/v1/xy93px60"))
Expand Down
8 changes: 6 additions & 2 deletions qlit/test_skos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rdflib import Graph, URIRef, Literal, RDF, SKOS
from rdflib import Graph, URIRef, Literal, DCTERMS, RDF, SKOS
from .skos import skos_validate_partial, skos_validate_graph, skos_complete_graph
from .thesaurus import Thesaurus

Expand Down Expand Up @@ -32,13 +32,16 @@ def test_skos_complete_graph():
t = Thesaurus()
food = URIRef("https://queerlit.dh.gu.se/qlit/v1/food")
fruit = URIRef("https://queerlit.dh.gu.se/qlit/v1/fruit")
friut = URIRef("https://queerlit.dh.gu.se/qlit/v1/friut")
vegetable = URIRef("https://queerlit.dh.gu.se/qlit/v1/vegetable")
t.add((food, RDF.type, SKOS.Concept))
t.add((fruit, RDF.type, SKOS.Concept))
t.add((friut, RDF.type, SKOS.Concept))
t.add((vegetable, RDF.type, SKOS.Concept))
t.add((food, SKOS.narrower, fruit))
t.add((vegetable, SKOS.broader, food))
t.add((vegetable, SKOS.related, fruit))
t.add((friut, DCTERMS.isReplacedBy, fruit))

skos_complete_graph(t)
assert (fruit, SKOS.inScheme, t.scheme) in t
Expand All @@ -47,4 +50,5 @@ def test_skos_complete_graph():
assert (fruit, SKOS.related, vegetable) in t
assert (food, SKOS.topConceptOf, t.scheme) in t
assert (fruit, SKOS.topConceptOf, t.scheme) not in t
assert (t.scheme, SKOS.hasTopConcept, food) in t
assert (t.scheme, SKOS.hasTopConcept, food) in t
assert (fruit, DCTERMS.replaces, friut) in t
5 changes: 4 additions & 1 deletion qlit/thesaurus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rdflib import RDF, SKOS, Graph, Literal, URIRef
from rdflib import RDF, OWL, SKOS, Graph, Literal, URIRef

BASE = 'https://queerlit.dh.gu.se/qlit/v1/'

Expand Down Expand Up @@ -39,6 +39,9 @@ def terms_if(self, f) -> Termset:
g = Termset(base=self.base)
for term in self.refs():
if f(term):
# Skip any deprecated term.
if self.value(term, OWL.deprecated):
continue;
g += self.triples((term, None, None))
return g

Expand Down

0 comments on commit aa9a879

Please sign in to comment.