use of com.hp.hpl.jena.rdf.model.Resource in project cdmlib by cybertaxonomy.
the class StructureTreeOwlImport method createNode.
private <T extends DefinedTermBase> void createNode(TermNode<T> parent, Statement nodeStatement, String treeLabel, Model model, StructureTreeOwlImportState state) {
if (state.getConfig().getProgressMonitor().isCanceled()) {
return;
}
Resource nodeResource = model.createResource(nodeStatement.getObject().toString());
UUID nodeUuid = UUID.fromString(nodeResource.getProperty(OwlUtil.propUuid).getString());
Resource termResource = nodeResource.getPropertyResourceValue(OwlUtil.propHasTerm);
TermNode<?> termNode = getTermNodeService().load(nodeUuid);
if (termNode == null) {
// import term vocabulary
Resource vocabularyResource = termResource.getPropertyResourceValue(OwlUtil.propHasVocabulary);
UUID vocUuid = UUID.fromString(vocabularyResource.getProperty(OwlUtil.propUuid).getString());
TermVocabulary vocabulary = getVocabularyService().load(vocUuid);
if (vocabulary == null) {
vocabulary = OwlImportUtil.createVocabulary(vocabularyResource, this, model, state);
vocabulary = getVocabularyService().save(vocabulary);
}
// import term
UUID termUuid = UUID.fromString(termResource.getProperty(OwlUtil.propUuid).getString());
T term = (T) getTermService().find(termUuid);
if (term == null) {
term = (T) OwlImportUtil.createTerm(termResource, this, model, state);
term = getTermService().save(term);
// only add term if it does not already exist
vocabulary.addTerm(term);
}
getVocabularyService().saveOrUpdate(vocabulary);
termNode = parent.addChild(term);
termNode.setUuid(nodeUuid);
// inapplicable if
StmtIterator inapplicableIterator = nodeResource.listProperties(OwlUtil.propNodeIsInapplicableIf);
while (inapplicableIterator.hasNext()) {
Statement statement = inapplicableIterator.next();
FeatureState featureState = createFeatureState(statement, model, state);
termNode.addInapplicableState(featureState);
}
// only applicable if
StmtIterator onlyApplicableIterator = nodeResource.listProperties(OwlUtil.propNodeIsOnlyApplicableIf);
while (onlyApplicableIterator.hasNext()) {
Statement statement = onlyApplicableIterator.next();
FeatureState featureState = createFeatureState(statement, model, state);
termNode.addApplicableState(featureState);
}
}
state.getConfig().getProgressMonitor().worked(1);
StmtIterator listProperties = nodeResource.listProperties(OwlUtil.propHasSubStructure);
while (listProperties.hasNext()) {
Statement prop = listProperties.next();
createNode(termNode, prop, treeLabel, model, state);
}
}
use of com.hp.hpl.jena.rdf.model.Resource in project cdmlib by cybertaxonomy.
the class OwlExportUtil method createNodeResource.
static Resource createNodeResource(TermNode<?> node, boolean initFeatureTree, ICdmRepository repo, StructureTreeOwlExportState state) {
if (initFeatureTree) {
createFeatureTreeResource(node.getGraph(), repo, state);
return getNodeResource(node, state);
}
Resource nodeResource = getNodeResource(node, state).addProperty(OwlUtil.propIsA, OwlUtil.NODE).addProperty(OwlUtil.propUuid, node.getUuid().toString());
// inapplicable if
Set<FeatureState> inapplicableIf = node.getInapplicableIf();
for (FeatureState featureState : inapplicableIf) {
Resource featureStateResource = state.getModel().createResource(OwlUtil.RESOURCE_SOURCE + featureState.getUuid()).addProperty(OwlUtil.propIsA, OwlUtil.FEATURE_STATE).addProperty(OwlUtil.propUuid, featureState.getUuid().toString()).addProperty(OwlUtil.propFeatureStateHasFeature, createTermResource(featureState.getFeature(), false, repo, state)).addProperty(OwlUtil.propFeatureStateHasState, createTermResource(featureState.getState(), false, repo, state));
nodeResource.addProperty(OwlUtil.propNodeIsInapplicableIf, featureStateResource);
}
// only applicable if
Set<FeatureState> onlyApplicableIf = node.getOnlyApplicableIf();
for (FeatureState featureState : onlyApplicableIf) {
Resource featureStateResource = state.getModel().createResource(OwlUtil.RESOURCE_SOURCE + featureState.getUuid()).addProperty(OwlUtil.propIsA, OwlUtil.FEATURE_STATE).addProperty(OwlUtil.propUuid, featureState.getUuid().toString()).addProperty(OwlUtil.propFeatureStateHasFeature, createTermResource(featureState.getFeature(), false, repo, state)).addProperty(OwlUtil.propFeatureStateHasState, createTermResource(featureState.getState(), false, repo, state));
nodeResource.addProperty(OwlUtil.propNodeIsOnlyApplicableIf, featureStateResource);
}
if (node.getTerm() != null) {
// add term to node
createVocabularyResource(node.getTerm().getVocabulary(), repo, state);
Resource termResource = OwlExportUtil.getTermResource(node.getTerm(), state);
nodeResource.addProperty(OwlUtil.propHasTerm, termResource);
}
return nodeResource;
}
use of com.hp.hpl.jena.rdf.model.Resource in project cdmlib by cybertaxonomy.
the class OwlExportUtil method addTerm.
private static Resource addTerm(DefinedTermBase term, Resource vocabularyResource, ICdmRepository repo, StructureTreeOwlExportState state) {
Resource termResource = OwlExportUtil.createTermResource(term, false, repo, state);
// add vocabulary to term
termResource.addProperty(OwlUtil.propHasVocabulary, vocabularyResource);
// add term to vocabulary
vocabularyResource.addProperty(OwlUtil.propHasTerm, termResource);
// export includes and generalizationOf
Set<DefinedTermBase> generalizationOf = term.getGeneralizationOf();
for (DefinedTermBase<?> kindOf : generalizationOf) {
Resource kindOfResource = addTerm(kindOf, vocabularyResource, repo, state);
termResource.addProperty(OwlUtil.propTermIsGeneralizationOf, kindOfResource);
}
Set<DefinedTermBase> includes = term.getIncludes();
for (DefinedTermBase<?> partOf : includes) {
Resource partOfResource = addTerm(partOf, vocabularyResource, repo, state);
termResource.addProperty(OwlUtil.propTermIncludes, partOfResource);
}
return termResource;
}
use of com.hp.hpl.jena.rdf.model.Resource in project cdmlib by cybertaxonomy.
the class OwlExportUtil method createVocabularyResource.
static Resource createVocabularyResource(TermVocabulary<?> vocabulary, ICdmRepository repo, StructureTreeOwlExportState state) {
String vocabularyResourceUri = getVocabularyResourceUri(vocabulary, state);
// check if vocabulary exists
if (state.getModel().containsResource(ResourceFactory.createResource(vocabularyResourceUri))) {
return state.getModel().createResource(vocabularyResourceUri);
}
// create vocabulary resource
Resource vocabularyResource = state.getModel().createResource(vocabularyResourceUri).addProperty(OwlUtil.propUuid, vocabulary.getUuid().toString()).addProperty(OwlUtil.propType, vocabulary.getTermType().getKey()).addProperty(OwlUtil.propIsA, OwlUtil.VOCABULARY);
if (vocabulary.getUri() != null) {
vocabularyResource.addProperty(OwlUtil.propUri, vocabulary.getUri().toString());
}
// add vocabulary representations
List<Resource> vocabularyRepresentationResources = OwlExportUtil.createRepresentationResources(vocabulary, state);
vocabularyRepresentationResources.forEach(rep -> vocabularyResource.addProperty(OwlUtil.propHasRepresentation, rep));
// add terms
Collection<TermDto> topLevelTerms = repo.getVocabularyService().getTopLevelTerms(vocabulary.getUuid());
for (TermDto termDto : topLevelTerms) {
if (state.getConfig().getProgressMonitor().isCanceled()) {
break;
}
addTopLevelTerm(termDto, vocabularyResource, repo, state);
}
return vocabularyResource;
}
use of com.hp.hpl.jena.rdf.model.Resource in project cdmlib by cybertaxonomy.
the class OwlExportUtil method addChildNode.
private static void addChildNode(TermNode parentNode, Resource parentResourceNode, ICdmRepository repo, StructureTreeOwlExportState state) {
List<TermNode> childNodes = parentNode.getChildNodes();
for (TermNode child : childNodes) {
// create node resource with term
Resource nodeResource = OwlExportUtil.createNodeResource(child, false, repo, state);
// add node to parent node
parentResourceNode.addProperty(OwlUtil.propHasSubStructure, nodeResource);
addChildNode(child, nodeResource, repo, state);
}
}
Aggregations