Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions librisxl-tools/elasticsearch/libris_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,6 @@
}
}
},
"hasTitle": {
"type": "nested",
"include_in_parent": true,
"properties": {
"@type": {"type": "keyword"},
"__mainTitle": {
"type": "text",
"analyzer": "softmatcher",
"copy_to": "_all",
"fields": {
"keyword": {
"type": "icu_collation_keyword",
"language": "sv"
}
}
}
}
},
"reverseLinks": {
"properties": {
"@type": {
Expand Down Expand Up @@ -408,8 +390,10 @@
"contribution",
"instanceOf.contribution",
"@reverse.instanceOf.contribution",

"hasPart.contribution",
"instanceOf.hasPart.contribution",

"relationship.entity.contribution",
"instanceOf.relationship.entity.contribution"
],
Expand All @@ -419,6 +403,50 @@
}
}
},
{
"hasTitle_template": {
"path_match": [
"hasTitle",
"instanceOf.hasTitle",
"@reverse.instanceOf.hasTitle",

"translationOf.hasTitle",
"instanceOf.translationOf.hasTitle",

"hasPart.hasTitle",
"instanceOf.hasPart.hasTitle",
"@reverse.instanceOf.hasPart.hasTitle",

"hasPart.translationOf.hasTitle",
"instanceOf.hasPart.translationOf.hasTitle",

"relationship.entity.hasTitle",
"instanceOf.relationship.entity.hasTitle",
"@reverse.instanceOf.relationship.entity.hasTitle",

"seriesMembership.inSeries.instanceOf.hasTitle",
"@reverse.instanceOf.seriesMembership.inSeries.instanceOf.hasTitle"
],
"mapping": {
"type": "nested",
"include_in_parent": true,
"properties": {
"@type": {"type": "keyword"},
"__mainTitle": {
"type": "text",
"analyzer": "softmatcher",
"copy_to": "_all",
"fields": {
"keyword": {
"type": "icu_collation_keyword",
"language": "sv"
}
}
}
}
}
}
},
{
"identifiedBy_template": {
"path_match": ["identifiedBy", "@reverse.instanceOf.identifiedBy"],
Expand Down
34 changes: 16 additions & 18 deletions whelk-core/src/main/groovy/whelk/search2/querytree/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -61,7 +62,7 @@ public List<Selector> getAltSelectors(JsonLd jsonLd, Collection<String> rdfSubje
altSelectors.add(new Path(l));
}
});
return excludeInverseIntegralRoundTrips(altSelectors);
return altSelectors;
}

private List<List<PathElement>> getAltPaths(List<? extends PathElement> tail, JsonLd jsonLd, Collection<String> rdfSubjectTypes, boolean allowIncompatible) {
Expand All @@ -71,27 +72,24 @@ private List<List<PathElement>> getAltPaths(List<? extends PathElement> tail, Js
var next = tail.getFirst();
var newTail = tail.subList(1, tail.size());
var nextAltSelectors = next.getAltSelectors(jsonLd, rdfSubjectTypes, allowIncompatible);

var shouldRecurse = (!newTail.isEmpty() && newTail.getFirst().isComposite())
|| (next instanceof Property p && "hasItem".equals(p.name()));

if (shouldRecurse) {
return nextAltSelectors.stream()
.flatMap(s -> getAltPaths(newTail, jsonLd, next.range(), allowIncompatible).stream()
.map(altPath -> concat(s.path(), altPath)))
.toList();
}

return nextAltSelectors.stream()
.flatMap(s -> getAltPaths(newTail, jsonLd, next.range(), allowIncompatible).stream()
.map(altPath -> Stream.concat(s.path().stream(), altPath.stream())))
.map(Stream::toList)
.map(s -> concat(s.path(), newTail))
.toList();
}

private List<Selector> excludeInverseIntegralRoundTrips(List<Selector> altSelectors) {
List<Selector> res = new ArrayList<>();
for (Selector s : altSelectors) {
List<Property.IntegralProperty> integralsInPath = s.path().stream()
.filter(Property.IntegralProperty.class::isInstance)
.map(Property.IntegralProperty.class::cast)
.toList();
boolean hasInversePair = integralsInPath.stream()
.anyMatch(integral -> integralsInPath.stream().anyMatch(integral::isInverseOf));
if (!hasInversePair) {
res.add(s);
}
}
return res;
private List<PathElement> concat(List<? extends PathElement> left, List<? extends PathElement> right) {
return Stream.concat(left.stream(), right.stream()).toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ class SelectorSpec extends Specification {
p.getAltSelectors(jsonLd, types, true).collect { it.path().collect { it.toString() }.join(".") } == result

where:
_p | types | result
"p1" | [] | ["p1"]
"p1" | ["T1"] | ["instanceOf.p1", "p1"]
"p1" | ["T2"] | ["hasInstance.p1", "p1"]
"p1" | ["T1", "T2"] | ["hasInstance.p1", "instanceOf.p1", "p1"]
"p1" | ["T3"] | ["p1"]
"p7" | ["T1"] | ["p7"]
"p7" | ["T2"] | ["hasInstance.p7"]
"p7" | ["T1", "T2"] | ["hasInstance.p7", "p7"]
"p7" | ["T3"] | ["p7"]
"p8" | ["T1"] | ["instanceOf.p8"]
"p8" | ["T2"] | ["p8"]
"p8" | ["T1", "T2"] | ["instanceOf.p8", "p8"]
"p8" | ["T3"] | ["p8"]
"p9" | ["T1"] | ["p9"]
"p9" | ["T2"] | ["p9"]
"p9" | ["T1", "T2"] | ["p9"]
"p9" | ["T3"] | ["p9"]
"hasInstance.p7" | ["T2"] | ["hasInstance.p7"]
"type" | ["T2"] | ["rdf:type"]
"instanceOf.p8" | ["T1"] | ["instanceOf.p8"]
"type" | ["T1"] | ["rdf:type"]
"p7.p14" | ["T2"] | ["hasInstance.p7.hasComponent.p14", "hasInstance.p7.p14"]
_p | types | result
"p1" | [] | ["p1"]
"p1" | ["T1"] | ["instanceOf.p1", "p1"]
"p1" | ["T2"] | ["hasInstance.p1", "p1"]
"p1" | ["T1", "T2"] | ["hasInstance.p1", "instanceOf.p1", "p1"]
"p1" | ["T3"] | ["p1"]
"hasItem" | ["T1"] | ["hasItem"]
"hasItem" | ["T2"] | ["hasInstance.hasItem"]
"hasItem" | ["T1", "T2"] | ["hasInstance.hasItem", "hasItem"]
"hasItem" | ["T3"] | ["hasItem"]
"p8" | ["T1"] | ["instanceOf.p8"]
"p8" | ["T2"] | ["p8"]
"p8" | ["T1", "T2"] | ["instanceOf.p8", "p8"]
"p8" | ["T3"] | ["p8"]
"p9" | ["T1"] | ["p9"]
"p9" | ["T2"] | ["p9"]
"p9" | ["T1", "T2"] | ["p9"]
"p9" | ["T3"] | ["p9"]
"hasInstance.hasItem" | ["T2"] | ["hasInstance.hasItem"]
"type" | ["T2"] | ["rdf:type"]
"instanceOf.p8" | ["T1"] | ["instanceOf.p8"]
"type" | ["T1"] | ["rdf:type"]
"hasItem.p14" | ["T2"] | ["hasInstance.hasItem.hasComponent.p14", "hasInstance.hasItem.p14"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TestData {
'rdf:type' : ['rdf:type'] as Set,
'instanceof' : ['instanceOf'] as Set,
'hasinstance' : ['hasInstance'] as Set,
'hasitem' : ['hasItem'] as Set,
'p' : ['p', 'p1'] as Set,
'plabel' : ['p2', 'p3'] as Set,
'pp' : ['p3', 'p4'] as Set,
Expand Down Expand Up @@ -227,6 +228,12 @@ class TestData {
'domain' : ['@id': 'T4'],
'range' : ['@id': 'T4']
],
[
'@id' : 'hasItem',
'@type' : 'DatatypeProperty',
'domain': [['@id': 'T1']],
'range' : [['@id': 'T4']]
],
[
'@id' : 'librissearch:workCategory',
'category' : ['@id': "https://id.kb.se/ns/librissearch/composite"],
Expand Down
Loading