Improving support for model knowledge
This commit is contained in:
parent
f4761c0a6f
commit
3895abdac3
|
@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Information System Model
|
||||
|
||||
## [v7.1.0-SNAPSHOT]
|
||||
|
||||
- Improved support for model knowledge [#25922]
|
||||
|
||||
## [v7.0.0]
|
||||
|
||||
- Reorganized E/R format [#24992]
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>information-system-model</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<version>7.1.0-SNAPSHOT</version>
|
||||
<name>Information System Model</name>
|
||||
<description>Information System Model is the reference model of the gCube Information System</description>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.discovery.knowledge;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.tree.NodeInformation;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
|
@ -35,4 +36,14 @@ public class ClassInformation implements NodeInformation<Class<Element>> {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType(Class<Element> clz) {
|
||||
return AccessType.getAccessType(clz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Element> getRoot(AccessType accessType) {
|
||||
return accessType.getTypeClass();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
package org.gcube.informationsystem.knowledge;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.tree.NodeInformation;
|
||||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
|
||||
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ModelKnowledge<T, NI extends NodeInformation<T>> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ModelKnowledge.class);
|
||||
|
||||
protected NI nodeInformation;
|
||||
protected Map<AccessType, Tree<T>> trees;
|
||||
protected Map<AccessType, UsageKnowledge<?>> usageKnowledges;
|
||||
|
||||
public ModelKnowledge() {
|
||||
reset();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
|
||||
this.trees = new HashMap<>();
|
||||
this.usageKnowledges = new HashMap<>();
|
||||
|
||||
AccessType[] modelTypes = AccessType.getModelTypes();
|
||||
for(AccessType accessType : modelTypes) {
|
||||
T t = nodeInformation.getRoot(accessType);
|
||||
|
||||
Tree<T> tree = new Tree<>(t, nodeInformation);
|
||||
trees.put(accessType, tree);
|
||||
|
||||
UsageKnowledge<?> usageKnowledge;
|
||||
if(accessType == AccessType.PROPERTY) {
|
||||
/*
|
||||
* In this case we get the type which uses such a property
|
||||
* and the property definition.
|
||||
* In this way we have a complete overview of the usege of the
|
||||
* property type
|
||||
*/
|
||||
usageKnowledge = new UsageKnowledge<Map<T,PropertyDefinition>>(accessType);
|
||||
}else {
|
||||
usageKnowledge = new UsageKnowledge<LinkedEntity>(accessType);
|
||||
}
|
||||
usageKnowledges.put(accessType, usageKnowledge);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void add(LinkedEntity linkedEntity, UsageKnowledge<LinkedEntity> relationUsage, UsageKnowledge<LinkedEntity> targetEntityUsage) {
|
||||
if (linkedEntity != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
UsageKnowledge<LinkedEntity> resourceUsage = (UsageKnowledge<LinkedEntity>) usageKnowledges.get(AccessType.RESOURCE);
|
||||
String source = linkedEntity.getSource();
|
||||
resourceUsage.add(source, linkedEntity);
|
||||
String relation = linkedEntity.getRelation();
|
||||
relationUsage.add(relation, linkedEntity);
|
||||
String target = linkedEntity.getTarget();
|
||||
targetEntityUsage.add(target, linkedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addAll(Collection<LinkedEntity> linkedEntities, UsageKnowledge<LinkedEntity> relationUsage, UsageKnowledge<LinkedEntity> targetEntityUsage) {
|
||||
if(linkedEntities!=null) {
|
||||
for(LinkedEntity le : linkedEntities) {
|
||||
add(le, relationUsage, targetEntityUsage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addPropertyUsage(Set<PropertyDefinition> properties, UsageKnowledge<PropertyDefinition> propertyUsage) {
|
||||
// for()
|
||||
}
|
||||
|
||||
public void addType(T t) {
|
||||
AccessType accessType = nodeInformation.getAccessType(t);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
UsageKnowledge<PropertyDefinition> propertyUsage = (UsageKnowledge<PropertyDefinition>) usageKnowledges.get(AccessType.PROPERTY);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
UsageKnowledge<LinkedEntity> resourceUsage = (UsageKnowledge<LinkedEntity>) usageKnowledges.get(AccessType.RESOURCE);
|
||||
@SuppressWarnings("unchecked")
|
||||
UsageKnowledge<LinkedEntity> facetUsage = (UsageKnowledge<LinkedEntity>) usageKnowledges.get(AccessType.FACET);
|
||||
@SuppressWarnings("unchecked")
|
||||
UsageKnowledge<LinkedEntity> isRelatedToUsage = (UsageKnowledge<LinkedEntity>) usageKnowledges.get(AccessType.IS_RELATED_TO);
|
||||
@SuppressWarnings("unchecked")
|
||||
UsageKnowledge<LinkedEntity> consistsOfUsage = (UsageKnowledge<LinkedEntity>) usageKnowledges.get(AccessType.CONSISTS_OF);
|
||||
|
||||
switch (accessType) {
|
||||
case PROPERTY:
|
||||
// Nothing to do
|
||||
break;
|
||||
|
||||
case RESOURCE:
|
||||
ResourceType resourceType = (ResourceType) t;
|
||||
addAll(resourceType.getFacets(), consistsOfUsage, facetUsage);
|
||||
addAll(resourceType.getResources(), isRelatedToUsage, resourceUsage);
|
||||
break;
|
||||
|
||||
case FACET:
|
||||
FacetType facetType = (FacetType) t;
|
||||
addPropertyUsage(facetType.getProperties(), propertyUsage);
|
||||
break;
|
||||
|
||||
case IS_RELATED_TO:
|
||||
IsRelatedToType isRelatedToType = (IsRelatedToType) t;
|
||||
|
||||
break;
|
||||
|
||||
case CONSISTS_OF:
|
||||
ConsistsOfType consistsOfType = (ConsistsOfType) t;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(accessType == AccessType.RESOURCE) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Tree<T> getTree(AccessType accessType) {
|
||||
return trees.get(accessType);
|
||||
}
|
||||
|
||||
public UsageKnowledge<?> getUsageKnowledge(AccessType accessType) {
|
||||
return usageKnowledges.get(accessType);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.gcube.informationsystem.knowledge;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.tree.NodeInformation;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class TypeInformation implements NodeInformation<Type> {
|
||||
|
||||
@Override
|
||||
public String getIdentifier(Type type) {
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getParentIdentifiers(Type root, Type type) {
|
||||
if(type.getName().compareTo(root.getName())==0) {
|
||||
return new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
return type.getExtendedTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType(Type type) {
|
||||
return type.getAccessType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getRoot(AccessType accessType) {
|
||||
return TypeMapper.createTypeDefinition(accessType.getTypeClass());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package org.gcube.informationsystem.knowledge;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class UsageKnowledge<U> {
|
||||
|
||||
protected Map<String, Set<U>> map;
|
||||
|
||||
public UsageKnowledge(AccessType accessType){
|
||||
this.map = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public void add(String typeName, U u) {
|
||||
Set<U> list = map.get(typeName);
|
||||
if(list==null) {
|
||||
list = new TreeSet<>();
|
||||
map.put(typeName, list);
|
||||
}
|
||||
list.add(u);
|
||||
}
|
||||
|
||||
public Set<U> getUsage(String typeName){
|
||||
Set<U> list = map.get(typeName);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,10 +2,16 @@ package org.gcube.informationsystem.tree;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
|
||||
public interface NodeInformation<T> {
|
||||
|
||||
public abstract String getIdentifier(T t);
|
||||
public String getIdentifier(T t);
|
||||
|
||||
public abstract Set<String> getParentIdentifiers(T root, T t);
|
||||
public Set<String> getParentIdentifiers(T root, T t);
|
||||
|
||||
public AccessType getAccessType(T t);
|
||||
|
||||
public T getRoot(AccessType accessType);
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class Tree<T> {
|
|||
private NodeInformation<T> ni;
|
||||
private Map<String, Node<T>> locate;
|
||||
|
||||
public Tree(T t, NodeInformation<T> ni) throws Exception {
|
||||
public Tree(T t, NodeInformation<T> ni) {
|
||||
this.allowMultipleInheritance = true;
|
||||
this.ni = ni;
|
||||
this.locate = new HashMap<>();
|
||||
|
|
Loading…
Reference in New Issue