Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1563 - Allow configuring concept feature for properties #1564

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ private SPARQLQueryPrimaryConditions newQueryBuilder(ConceptFeatureValueType aVa
return SPARQLQueryBuilder.forClasses(aKB);
case INSTANCE:
return SPARQLQueryBuilder.forInstances(aKB);
case PROPERTY:
return SPARQLQueryBuilder.forProperties(aKB);
default:
throw new IllegalArgumentException("Unknown item type: [" + aValueType + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

public enum ConceptFeatureValueType
{
ANY_OBJECT("<Any Concept/Instance>"),
CONCEPT("Only Concepts"),
INSTANCE("Only Instances");
ANY_OBJECT("<any concept/instance>"),
CONCEPT("concepts only"),
INSTANCE("instances only"),
PROPERTY("properties only");

private final String uiLabel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ private SPARQLQueryBuilder(KnowledgeBase aKB, Mode aMode)
{
kb = aKB;
mode = aMode;

// The Wikidata search service we are using does not return properties, so we have to do
// this the old-fashioned way...
if (Mode.PROPERTY.equals(mode) && FTS_WIKIDATA.equals(aKB.getFullTextSearchIri())) {
forceDisableFTS = true;
}
}

private void addPattern(Priority aPriority, GraphPattern aPattern)
Expand Down Expand Up @@ -675,6 +681,8 @@ else if (FTS_WIKIDATA.equals(ftsMode)) {
addPattern(PRIMARY, withLabelMatchingExactlyAnyOf_Wikidata_FTS(aValues));
}
else if (FTS_NONE.equals(ftsMode) || ftsMode == null) {
// For exact matching, we do not make use of regexes, so we keep this as a primary
// condition - unlike in withLabelContainingAnyOf or withLabelStartingWith
addPattern(PRIMARY, withLabelMatchingExactlyAnyOf_No_FTS(aValues));
}
else {
Expand Down Expand Up @@ -831,7 +839,10 @@ else if (FTS_WIKIDATA.equals(ftsMode)) {
addPattern(PRIMARY, withLabelContainingAnyOf_Wikidata_FTS(aValues));
}
else if (FTS_NONE.equals(ftsMode) || ftsMode == null) {
addPattern(PRIMARY, withLabelContainingAnyOf_No_FTS(aValues));
// Label matching without FTS is slow, so we add this with low prio and hope that some
// other higher-prio condition exists which limites the number of candidates to a
// manageable level
addPattern(SECONDARY, withLabelContainingAnyOf_No_FTS(aValues));
}
else {
throw new IllegalStateException(
Expand Down Expand Up @@ -968,7 +979,6 @@ public SPARQLQueryBuilder withLabelStartingWith(String aPrefixQuery)
return this;
}


IRI ftsMode = forceDisableFTS ? FTS_NONE : kb.getFullTextSearchIri();

if (FTS_LUCENE.equals(ftsMode)) {
Expand All @@ -984,7 +994,10 @@ else if (FTS_WIKIDATA.equals(ftsMode)) {
addPattern(PRIMARY, withLabelStartingWith_Wikidata_FTS(aPrefixQuery));
}
else if (FTS_NONE.equals(ftsMode) || ftsMode == null) {
addPattern(PRIMARY, withLabelStartingWith_No_FTS(aPrefixQuery));
// Label matching without FTS is slow, so we add this with low prio and hope that some
// other higher-prio condition exists which limites the number of candidates to a
// manageable level
addPattern(SECONDARY, withLabelStartingWith_No_FTS(aPrefixQuery));
}
else {
throw new IllegalStateException(
Expand Down Expand Up @@ -1498,7 +1511,7 @@ public SelectQuery selectQuery()
GraphPatterns.and(concat(primaryPatterns.stream(), primaryRestrictions.stream())
.toArray(GraphPattern[]::new)).getQueryString()));

// Then add the optional elements
// Then add the optional or lower-prio elements
secondaryPatterns.stream().forEach(query::where);

if (serverSideReduce) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,42 @@ public void thatPropertyQueryLimitedToDescendantsDoesNotReturnOutOfScopeResults(
.containsExactlyInAnyOrder("http://example.org/#subproperty-1-1",
"http://example.org/#subproperty-1-1-1");
}

@Test
public void thatPropertyQueryListWorks_Wikidata()
{
assertIsReachable(wikidata);

kb.setType(REMOTE);
kb.setFullTextSearchIri(FTS_WIKIDATA);
initWikidataMapping();

List<KBHandle> results = asHandles(wikidata, SPARQLQueryBuilder
.forProperties(kb)
.limit(10));

assertThat(results).extracting(KBHandle::getIdentifier).doesNotHaveDuplicates();
assertThat(results).hasSize(10);
}

@Test
public void thatPropertyQueryLabelStartingWith_Wikidata()
{
assertIsReachable(wikidata);

kb.setType(REMOTE);
kb.setFullTextSearchIri(FTS_WIKIDATA);
initWikidataMapping();

List<KBHandle> results = asHandles(wikidata, SPARQLQueryBuilder
.forProperties(kb)
.withLabelStartingWith("educated"));

assertThat(results).extracting(KBHandle::getIdentifier).doesNotHaveDuplicates();
assertThat(results).isNotEmpty();
assertThat(results).extracting(KBHandle::getUiLabel)
.allMatch(label -> label.toLowerCase().startsWith("educated"));
}
@Test
public void thatPropertyQueryLimitedToChildrenDoesNotReturnOutOfScopeResults()
throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public List<FeatureType> getSupportedFeatureTypes(AnnotationLayer aAnnotationLay
{
// We just start with no specific scope at all (ANY) and let the user refine this via
// the traits editor
return asList(new FeatureType(TYPE_ANY_OBJECT, "KB: Concept/Instance", featureSupportId));
return asList(new FeatureType(TYPE_ANY_OBJECT, "KB: Concept/Instance/Property",
featureSupportId));
}

@Override
Expand Down