📄 kaonutils.java
字号:
package it.itc.ectrl.normkit.common;
import java.util.*;
import java.net.*;
import edu.unika.aifb.kaon.api.change.*;
import edu.unika.aifb.kaon.api.oimodel.*;
import edu.unika.aifb.kaon.api.KAONException;
import edu.unika.aifb.kaon.api.vocabulary.*;
/**
* Class that provides some usefull static functions to manipulate OIModels.
*
* @author Nuno Silva (Nuno.Silva@dei.isep.ipp.pt)
*/
public class KAONUtils
{
/**
* Returns the label of the node in the tree.
*
* @return label of the node in the tree
*/
static public String toString( Entity entity )
{
try
{
// Concept concept = (Concept) getUserObject();
String label = entity.getLabel(KAONVocabularyAdaptor.INSTANCE.getLanguageURI("en"));
if (label == null)
{
URL url = new URL( entity.getURI() );
label=url.getRef();
}
return label;
}
catch (Exception e)
{
// e.printStackTrace();
return "no-label";
}
}
public static Instance addConceptInstanceToOIModel(OIModel oimodel, String strURIConcept, String strURIInstance) throws KAONException
{
Concept concept = oimodel.getConcept(strURIConcept);
Instance instance = oimodel.getInstance(strURIInstance);
// ChangeList
List listChanges = new LinkedList();
listChanges.add( new AddEntity(instance) );
listChanges.add( new AddInstanceOf( concept, instance) );
// update target instances OIModel
oimodel.applyChanges( listChanges );
return instance;
}
/**
* Removes an instance of a specific concept from the specified OIModel.
*
* @oimodel the oimodel where the removal will occur.
* @strURIConcecept the concept URI where the property intances will be removed.
* @strURIInstance the concept instance URI that will be removed.
*/
public static void removeConceptInstanceFromOIModel( OIModel oimodel, String strURIConcept, String strURIInstance ) throws Exception
{
Concept concept = oimodel.getConcept(strURIConcept);
Instance instance = oimodel.getInstance(strURIInstance);
// ChangeList
List listChanges = new LinkedList();
listChanges.add( new RemoveInstanceOf( concept, instance ) );
// update target instances OIModel
oimodel.applyChanges( listChanges );
}
/**
* Add property value (either attribute or relation) to the concept, in the oimodel
*
* @oimodel the OI-Model that contains the concept
* @strURIConcept the Concept URI
* @strURIProperty the Property URI
* @strPropertyValue the property value, either attribute (string) or relation (valid and existent concept URI)
*
*/
public static void addPropertyValueToOIModel(OIModel oimodel, String strURIConcept, String strURIProperty, String strPropertyValue ) throws KAONException
{
Instance instance = oimodel.getInstance(strURIConcept);
Property property = oimodel.getProperty(strURIProperty);
PropertyInstance propertyInstance;
if( !property.isAttribute() )
{
// create property (relation) instance
Instance instanceReferenced = oimodel.getInstance(strPropertyValue);
propertyInstance = oimodel.getPropertyInstance(property, instance, instanceReferenced);
}
else
{
// get property (attribute) instance
propertyInstance = oimodel.getPropertyInstance(property, instance, strPropertyValue);
}
List listChanges = new LinkedList();
listChanges.add( new AddPropertyInstance(propertyInstance) );
oimodel.applyChanges(listChanges);
}
public static void addPropertyValueToOIInstanceModel(OIModel oimodel, OIModel oinstance, String strURIConcept, String strURIProperty, String strPropertyValue ) throws KAONException
{
Instance instance = oinstance.getInstance(strURIConcept);
Property property = oimodel.getProperty(strURIProperty);
PropertyInstance propertyInstance;
if( !property.isAttribute() )
{
// create property (relation) instance
Instance instanceReferenced = oinstance.getInstance(strPropertyValue);
propertyInstance = oinstance.getPropertyInstance(property, instance, instanceReferenced);
}
else
{
// get property (attribute) instance
propertyInstance = oinstance.getPropertyInstance(property, instance, strPropertyValue);
}
List listChanges = new LinkedList();
listChanges.add( new AddPropertyInstance(propertyInstance) );
oinstance.applyChanges(listChanges);
}
/**
* Removes a property instance from the specified OIModel.
*
* @oimodel the oimodel where the removal will occur.
* @strURIConcept the concept URI where the property intances will be removed.
* @strURIInstance the property value of the proeprty that will be removed.
*/
public static void removePropertyInstanceFromOIModel( OIModel oimodel, String strURIConcept,
String strURIProperty, String strPropertyValue ) throws Exception
{
Instance conceptInstance = oimodel.getInstance( strURIConcept );
Property property = oimodel.getProperty( strURIProperty );
Object propertyValue;
if( property.isAttribute() )
propertyValue = strPropertyValue;
else
propertyValue = oimodel.getInstance( strPropertyValue );
PropertyInstance propertyInstance = oimodel.getPropertyInstance( property, conceptInstance, propertyValue );
// ChangeList
List listChanges = new LinkedList();
listChanges.add( new RemovePropertyInstance( propertyInstance ) );
// update target instances OIModel
oimodel.applyChanges( listChanges );
}
public static void addPropertyValueToInstance( OIModel oimodelInstances,
OIModel oimodelOntology,
String strURIInstance,
String strURIProperty,
String strPropertyValue ) throws Exception
{
Instance instance = oimodelInstances.getInstance( strURIInstance );
Property property = oimodelOntology.getProperty( strURIProperty );
PropertyInstance propertyInstance;
if( !property.isAttribute() )
{
// create property (relation) instance
Instance instanceReferenced = oimodelInstances.getInstance( strPropertyValue );
propertyInstance = oimodelInstances.getPropertyInstance( property, instance, instanceReferenced );
}
else
{
// get property (attribute) instance
propertyInstance = oimodelInstances.getPropertyInstance(property, instance, strPropertyValue);
}
List listChanges = new LinkedList();
listChanges.add( new AddPropertyInstance(propertyInstance) );
oimodelInstances.applyChanges(listChanges);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -