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

Merge pull request #9 from swiss-art-research-net/main #10

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [4.3.0]

- Add aggregate lookup service
## [4.2.2]

- Add `clearable` option to the `semantic-form-checklist-input` component, which adds a button to clear the current selection.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ project.ext {
buildConfig = parseBuildConfig(project.file(buildJsonPath))
}

version = '4.2.2'
version = '4.3.0'
group = 'com.metaphacts'
project.ext.vendor = 'metaphacts GmbH'
project.ext.buildDate = new Date()
Expand Down
2 changes: 1 addition & 1 deletion buildDockerImage.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!\bin\bash

./build.sh -DbuildEnv=prod -Dbuildjson=./sari/sari-root-build.json -DplatformVersion=$1 platformWar
docker exec mp-dev bash -c "./build.sh -DbuildEnv=prod -Dbuildjson=./sari/sari-root-build.json -DplatformVersion=$1 platformWar"

export DOCKER_FOLDER="$(pwd)/metaphacts-platform/dist/docker"
cp target/platform-$1.war $DOCKER_FOLDER/platform/ROOT.war
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ <h3>Implementations</h3>
entity search API
</a> to provide best experience and performance.</td>
</tr>
<tr>
<td><a href="#FederatedLookupService">FederatedLookupService</a></td>
<td><code>metaphacts:federatedLookup</code></td>
<td>Delegates the lookup to one or more other lookup services, combining their results.</td>
</tr>
[[> lookupServiceExtensionsTable]]
</tbody>
</table>
Expand Down Expand Up @@ -468,6 +473,84 @@ <h4 id="FederatedLookupService">FederatedLookupService</h4>
]]></mp-code-block>


<h4 id="AggregatedLookupService">AggregatedLookupService</h4>

<p>
The <code>AggregatedLookupService</code> (type <code>rds:aggregationLookup</code>) orders the results of a delegated
lookup service by a given predicate. This can be used to group results by a given predicate, e.g. a <em>sameAs</em> relationship.
</p>

<p>
Results from the delegated service are reordered so that results that point to the same resource appear after each other.
In addition the lookup returns a <code>?reference</code> variable that contains the URI to the first resource in the group.
</p>

<p>Configuration example:</p>

<mp-code-block mode='text/turtle'><![CDATA[
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ms: <http://www.openrdf.org/config/sail/memory#> .
@prefix lookup: <http://www.metaphacts.com/ontologies/platform/repository/lookup#> .
@prefix rep: <http://www.openrdf.org/config/repository#> .
@prefix sail: <http://www.openrdf.org/config/sail#> .
@prefix sr: <http://www.openrdf.org/config/repository/sail#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix mph: <http://www.metaphacts.com/ontologies/platform/repository#> .
@prefix ephedra: <http://www.metaphacts.com/ontologies/platform/ephedra#> .
@prefix fedsail: <http://www.openrdf.org/config/sail/federation#> .
@prefix sparqlr: <http://www.openrdf.org/config/repository/sparql#> .

[] a rep:Repository;
rep:repositoryID "aggregated-lookup";
rdfs:label "Aggregation Lookup";
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository";
sr:sailImpl [
sail:sailType "openrdf:MemoryStore"
]
];
lookup:configuration [
lookup:type "rds:aggregationLookup";
lookup:targetRepository "default";
lookup:delegateService "default-federated-lookup";
lookup:sameAsPattern "<http://www.ics.forth.gr/isl/CRMdig/L54_is_same-as>"
] .
]]></mp-code-block>

<p>
The <code>?reference</code> variable can also be used to group the results in a <code>semantic-table</code>. e.g.
</p>

<mp-code-block>

<semantic-search limit=1000>
<semantic-search-keyword-prefetch
query='{
"type": "lookup",
"limit": 20,
"lookupServiceName": "aggregated-lookup"
}'>
</semantic-search-keyword-prefetch>

<semantic-search-result-holder>
<semantic-search-result>
<semantic-table
id='table'
options='{
"showFilter": false,
"groupingOptions": {"groupedBy": ["groupIri"]}
}'
query='SELECT * WHERE {
BIND(IF(BOUND(?reference), ?reference, ?subject) as ?groupIri)
} ORDER BY DESC(?score)'
>
</semantic-table>
</semantic-search-result>
</semantic-search-result-holder>
</semantic-search>


</mp-code-block>
<h4 id="GenericSparqlLookupService">Generic SPARQL</h4>

<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@
[[/inline]]

[[#*inline "lookupServiceExtensionsTable"]]
[[!-- No extensions --]]
<tr>
<td><a href="#AggregationLookup">AggregationLookup</a></td>
<td><code>rds:aggregationLookup</code></td>
<td>Aggregates results obtained through another lookup by a defined predicate.</td>
</tr>
[[/inline]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* "Commons Clause" License Condition v1.0
*
* The Software is provided to you by the Licensor under the
* License, as defined below, subject to the following condition.
*
* Without limiting other conditions in the License, the grant
* of rights under the License will not include, and the
* License does not grant to you, the right to Sell the Software.
*
* For purposes of the foregoing, "Sell" means practicing any
* or all of the rights granted to you under the License to
* provide to third parties, for a fee or other consideration
* (including without limitation fees for hosting or
* consulting/ support services related to the Software), a
* product or service whose value derives, entirely or substantially,
* from the functionality of the Software. Any
* license notice or attribution required by the License must
* also include this Commons Clause License Condition notice.
*
* License: LGPL 2.1 or later
* Licensor: metaphacts GmbH
*
* Copyright (C) 2015-2021, metaphacts GmbH
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, you can receive a copy
* of the GNU Lesser General Public License from http://www.gnu.org/
*/
package com.metaphacts.lookup.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.util.Models;

import com.metaphacts.lookup.impl.RepositoryBasedLookupConfig;
import com.metaphacts.lookup.spi.LookupServiceConfigException;

public class AggregationLookupConfig extends RepositoryBasedLookupConfig {
public static final IRI LOOKUP_DELEGATE_SERVICE = VF.createIRI(LOOKUP_NAMESPACE, "delegateService");
public static final IRI LOOKUP_SAMEAS_PATTERN = VF.createIRI(LOOKUP_NAMESPACE, "sameAsPattern");
public static final IRI LOOKUP_FILTER_SECONDARY_RESULTS = VF.createIRI(LOOKUP_NAMESPACE, "filterSecondaryResults");

protected Boolean filterSecondaryResults;
protected String delegateService;
protected List<String> sameAsPatterns;

public AggregationLookupConfig() {
super(AggregationLookupServiceFactory.LOOKUP_TYPE);
}

public void setFilterSecondaryResults(Boolean filterSecondaryResults) {
this.filterSecondaryResults = filterSecondaryResults;
}

public Boolean getFilterSecondaryResults() {
return filterSecondaryResults;
}

public boolean isFilterSecondaryResults() {
return (filterSecondaryResults != null ? filterSecondaryResults : false);
}

public void setDelegateService(String delegateService) {
this.delegateService = delegateService;
}

public String getDelegateService() {
return delegateService;
}

public List<String> getSameAsPatterns() {
return sameAsPatterns;
}

public void setSameAsPatterns(List<String> sameAsPatterns) {
this.sameAsPatterns = sameAsPatterns;
}

public void addSameAsPattern(String sameAsPattern) {
if (this.sameAsPatterns == null) {
this.sameAsPatterns = new ArrayList<>();
}
this.sameAsPatterns.add(sameAsPattern);
}

@Override
public Resource export(Model model) {
Resource implNode = super.export(model);

if (getFilterSecondaryResults() != null) {
model.add(implNode, LOOKUP_FILTER_SECONDARY_RESULTS, VF.createLiteral(getFilterSecondaryResults()));
}
if (getDelegateService() != null) {
model.add(implNode, LOOKUP_DELEGATE_SERVICE, VF.createLiteral(getDelegateService()));
}
Optional.ofNullable(getSameAsPatterns()).stream().flatMap(l -> l.stream())
.forEach(pattern -> model.add(implNode, LOOKUP_SAMEAS_PATTERN, VF.createLiteral(pattern)));

return implNode;
}

@Override
public void parse(Model model, Resource resource) throws LookupServiceConfigException {
super.parse(model, resource);

Models.objectLiteral(model.filter(resource, LOOKUP_FILTER_SECONDARY_RESULTS, null))
.ifPresent(literal -> setFilterSecondaryResults(literal.booleanValue()));
Models.objectLiteral(model.filter(resource, LOOKUP_DELEGATE_SERVICE, null))
.ifPresent(literal -> setDelegateService(literal.stringValue()));
Models.objectLiterals(model.filter(resource, LOOKUP_SAMEAS_PATTERN, null))
.forEach(literal -> addSameAsPattern((literal.stringValue())));
}

@Override
public void validate() throws LookupServiceConfigException {
super.validate();
if (getDelegateService() == null) {
throw new LookupServiceConfigException("No delegate service set!");
}
}
}
Loading