Skip to content

Commit

Permalink
Merge pull request #222 from kbss-cvut/development
Browse files Browse the repository at this point in the history
2.16.3 Release
  • Loading branch information
ledsoft committed Mar 22, 2023
2 parents 6873774 + 0591491 commit ebf5e9e
Show file tree
Hide file tree
Showing 26 changed files with 654 additions and 415 deletions.
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
<version>2.7.9</version>
</parent>

<artifactId>termit</artifactId>
<version>2.16.2</version>
<version>2.16.3</version>
<name>TermIt</name>
<description>Terminology manager based on Semantic Web technologies.</description>
<packaging>${packaging}</packaging>
Expand All @@ -25,10 +25,10 @@

<properties>
<java.version>11</java.version>
<org.apache.tika.tika-core.version>2.6.0</org.apache.tika.tika-core.version>
<org.apache.tika.tika-core.version>2.7.0</org.apache.tika.tika-core.version>
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
<cz.cvut.kbss.jopa.version>0.20.2</cz.cvut.kbss.jopa.version>
<cz.cvut.kbss.jsonld.version>0.11.1</cz.cvut.kbss.jsonld.version>
<cz.cvut.kbss.jopa.version>0.21.1</cz.cvut.kbss.jopa.version>
<cz.cvut.kbss.jsonld.version>0.12.0</cz.cvut.kbss.jsonld.version>
<org.aspectj.version>1.9.7</org.aspectj.version>

<!-- Default value for deployment type property which should otherwise specified on command line -->
Expand Down Expand Up @@ -250,7 +250,7 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.3</version>
<version>1.15.4</version>
</dependency>

<!-- Flexmark for handling Markdown -->
Expand Down Expand Up @@ -295,7 +295,7 @@
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-spring-boot-starter</artifactId>
<version>1.91.0</version>
<version>1.92.0</version>
</dependency>

<!-- Caching -->
Expand Down Expand Up @@ -431,9 +431,9 @@
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<version>1.13.1</version>
<configuration>
<complianceLevel>${java.version}</complianceLevel>
<source>${java.version}</source>
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/cz/cvut/kbss/termit/dto/RdfsResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
*/
package cz.cvut.kbss.termit.dto;

import cz.cvut.kbss.jopa.model.MultilingualString;
import cz.cvut.kbss.jopa.model.annotations.*;
import cz.cvut.kbss.jopa.vocabulary.RDFS;
import cz.cvut.kbss.ontodriver.model.LangString;
import cz.cvut.kbss.termit.model.util.HasTypes;

import java.io.Serializable;
Expand All @@ -35,9 +37,9 @@
@VariableResult(name = "x",
type = URI.class),
@VariableResult(name = "label",
type = String.class),
type = LangString.class),
@VariableResult(name = "comment",
type = String.class),
type = LangString.class),
@VariableResult(name = "type",
type = String.class)
})})
Expand All @@ -48,21 +50,25 @@ public class RdfsResource implements Serializable, HasTypes {
private URI uri;

@OWLAnnotationProperty(iri = RDFS.LABEL)
private String label;
private MultilingualString label;

@OWLAnnotationProperty(iri = RDFS.COMMENT)
private String comment;
private MultilingualString comment;

@Types
private Set<String> types;

public RdfsResource() {
}

public RdfsResource(URI uri, String label, String comment, String type) {
public RdfsResource(URI uri, LangString label, LangString comment, String type) {
this.uri = uri;
this.label = label;
this.comment = comment;
if (label != null) {
this.label = MultilingualString.create(label.getValue(), label.getLanguage().orElse(null));
}
if (comment != null) {
this.comment = MultilingualString.create(comment.getValue(), comment.getLanguage().orElse(null));
}
this.types = Collections.singleton(type);
}

Expand All @@ -74,19 +80,19 @@ public void setUri(URI uri) {
this.uri = uri;
}

public String getLabel() {
public MultilingualString getLabel() {
return label;
}

public void setLabel(String label) {
public void setLabel(MultilingualString label) {
this.label = label;
}

public String getComment() {
public MultilingualString getComment() {
return comment;
}

public void setComment(String comment) {
public void setComment(MultilingualString comment) {
this.comment = comment;
}

Expand Down Expand Up @@ -123,7 +129,7 @@ public int hashCode() {
public String toString() {
return "RdfsResource{" +
"uri=" + uri +
", label='" + label + '\'' +
", label=" + label +
", types=" + types +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,4 @@ public Map<String, Set<String>> getProperties() {
public void setProperties(final Map<String, Set<String>> properties) {
this.properties = properties;
}

@Override
public String toString() {
return "ReadOnlyTerm{" +
getLabel() +
" <" + getUri() + '>' +
", types=" + getTypes() +
'}';
}
}
10 changes: 10 additions & 0 deletions src/main/java/cz/cvut/kbss/termit/model/AbstractTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cz.cvut.kbss.termit.model.util.AssetVisitor;
import cz.cvut.kbss.termit.model.util.HasTypes;
import cz.cvut.kbss.termit.model.util.SupportsSnapshots;
import cz.cvut.kbss.termit.util.Utils;
import cz.cvut.kbss.termit.util.Vocabulary;
import cz.cvut.kbss.termit.validation.PrimaryNotBlank;

Expand Down Expand Up @@ -157,4 +158,13 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(getUri());
}

@Override
public String toString() {
return getClass().getSimpleName() + "{" +
getLabel() + ' ' +
Utils.uriToString(getUri()) +
", types=" + getTypes() +
'}';
}
}
9 changes: 0 additions & 9 deletions src/main/java/cz/cvut/kbss/termit/model/Term.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,4 @@ public void splitExternalAndInternalParents() {
this.parentTerms = parents;
this.externalParentTerms = externalParents;
}

@Override
public String toString() {
return "Term{" +
getLabel() +
" <" + getUri() + '>' +
", types=" + getTypes() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface VocabularyContextMapper {
/**
* Gets identifier of the repository context in which the specified vocabulary is stored.
*
* @param vocabulary Vocabulary whose context to retrieve
* @param vocabulary Vocabulary whose context to retrieve. A reference is sufficient
* @return Repository context identifier
*/
default URI getVocabularyContext(Vocabulary vocabulary) {
Expand Down
30 changes: 23 additions & 7 deletions src/main/java/cz/cvut/kbss/termit/persistence/dao/DataDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@

import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

@Repository
Expand All @@ -65,7 +62,7 @@ public DataDao(EntityManager em, Configuration config) {
* @return List of properties, ordered by label
*/
public List<RdfsResource> findAllProperties() {
return em.createNativeQuery("SELECT ?x ?label ?comment ?type WHERE {" +
final List<RdfsResource> result = em.createNativeQuery("SELECT ?x ?label ?comment ?type WHERE {" +
"BIND (?property as ?type)" +
"?x a ?type ." +
"OPTIONAL { ?x ?has-label ?label . }" +
Expand All @@ -74,6 +71,25 @@ public List<RdfsResource> findAllProperties() {
.setParameter("property", URI.create(RDF.PROPERTY))
.setParameter("has-label", RDFS_LABEL)
.setParameter("has-comment", URI.create(RDFS.COMMENT)).getResultList();
return consolidateTranslations(result);
}

private static List<RdfsResource> consolidateTranslations(List<RdfsResource> queryResult) {
final Map<URI, RdfsResource> map = new LinkedHashMap<>(queryResult.size());
queryResult.forEach(r -> {
if (!map.containsKey(r.getUri())) {
map.put(r.getUri(), r);
} else {
final RdfsResource res = map.get(r.getUri());
if (r.getLabel() != null) {
res.getLabel().getValue().putAll(r.getLabel().getValue());
}
if (r.getComment() != null) {
res.getComment().getValue().putAll(r.getComment().getValue());
}
}
});
return new ArrayList<>(map.values());
}

/**
Expand Down Expand Up @@ -101,14 +117,14 @@ public void persist(RdfsResource instance) {
*/
public Optional<RdfsResource> find(URI id) {
Objects.requireNonNull(id);
final List<RdfsResource> resources = em.createNativeQuery("SELECT ?x ?label ?comment ?type WHERE {" +
final List<RdfsResource> resources = consolidateTranslations(em.createNativeQuery("SELECT ?x ?label ?comment ?type WHERE {" +
"BIND (?id AS ?x)" +
"?x a ?type ." +
"OPTIONAL { ?x ?has-label ?label .}" +
"OPTIONAL { ?x ?has-comment ?comment . }" +
"}", "RdfsResource").setParameter("id", id)
.setParameter("has-label", RDFS_LABEL)
.setParameter("has-comment", URI.create(RDFS.COMMENT)).getResultList();
.setParameter("has-comment", URI.create(RDFS.COMMENT)).getResultList());
if (resources.isEmpty()) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ private void evictCachedSubTerms(Set<? extends AbstractTerm> originalParents,
newCopy.forEach(t -> subTermsCache.evict(t.getUri()));
}

/**
* Finds all terms in the specified vocabulary, regardless of their position in the term hierarchy.
*
* @param vocabulary Vocabulary whose terms to retrieve. A reference is sufficient
* @return List of vocabulary term DTOs
*/
public List<TermDto> findAll(Vocabulary vocabulary) {
Objects.requireNonNull(vocabulary);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cz.cvut.kbss.jopa.model.MultilingualString;
import cz.cvut.kbss.termit.exception.TermItException;
import cz.cvut.kbss.termit.model.validation.ValidationResult;
import cz.cvut.kbss.termit.persistence.context.VocabularyContextMapper;
import cz.cvut.kbss.termit.util.Configuration;
import cz.cvut.kbss.termit.util.Utils;
import org.apache.jena.rdf.model.Literal;
Expand All @@ -13,6 +14,7 @@
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.util.FileUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.rio.turtle.TurtleWriter;
Expand Down Expand Up @@ -54,13 +56,17 @@ public class Validator implements VocabularyContentValidator {
private static final Set<String> MODEL_RULES_TO_ADD = Set.of("m1.ttl", "m2.ttl");

private final EntityManager em;
private final VocabularyContextMapper vocabularyContextMapper;

private com.github.sgov.server.Validator validator;
private Model validationModel;

@Autowired
public Validator(EntityManager em, Configuration config) {
public Validator(EntityManager em,
VocabularyContextMapper vocabularyContextMapper,
Configuration config) {
this.em = em;
this.vocabularyContextMapper = vocabularyContextMapper;
initValidator(config.getPersistence().getLanguage());
}

Expand Down Expand Up @@ -149,9 +155,11 @@ private Model getModelFromRdf4jRepository(final Collection<URI> vocabularyIris)
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final OutputStreamWriter writer = new OutputStreamWriter(baos, StandardCharsets.UTF_8);
final Repository repository = em.unwrap(Repository.class);
final ValueFactory vf = repository.getValueFactory();
try (final RepositoryConnection c = repository.getConnection()) {
final List<IRI> iris = new ArrayList<>();
vocabularyIris.forEach(i -> iris.add(repository.getValueFactory().createIRI(i.toString())));
vocabularyIris.forEach(
i -> iris.add(vf.createIRI(vocabularyContextMapper.getVocabularyContext(i).toString())));
c.export(new TurtleWriter(writer), iris.toArray(new IRI[]{}));
writer.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public TermService(VocabularyExporters exporters, VocabularyService vocabularySe
* If export into the specified media type is not supported, an empty {@link Optional} is returned.
*
* @param vocabulary Vocabulary to export
* @param config Expected media type of the export
* @param config Expected media type of the export
* @return Exported resource wrapped in an {@code Optional}
*/
public Optional<TypeAwareResource> exportGlossary(Vocabulary vocabulary, ExportConfig config) {
Expand All @@ -91,7 +91,7 @@ public Optional<TypeAwareResource> exportGlossary(Vocabulary vocabulary, ExportC
/**
* Retrieves all terms from the specified vocabulary.
*
* @param vocabulary Vocabulary whose terms will be returned
* @param vocabulary Vocabulary whose terms will be returned. A reference is sufficient
* @return Matching terms
*/
public List<TermDto> findAll(Vocabulary vocabulary) {
Expand Down Expand Up @@ -394,7 +394,7 @@ public void remove(Term term) {
* during the analysis).
*
* @param term Term to analyze
* @param vocabularyContext Identifier of the vocabulary used for analysis
* @param vocabularyContext Identifier of the repository context of the vocabulary used for analysis
*/
public void analyzeTermDefinition(AbstractTerm term, URI vocabularyContext) {
Objects.requireNonNull(term);
Expand Down
Loading

0 comments on commit ebf5e9e

Please sign in to comment.