本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.createResource方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.createResource方法的具體用法?Java OntModel.createResource怎麽用?Java OntModel.createResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.createResource方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addImport
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Override
public boolean addImport(String modelName, String importedModelUri) throws ConfigurationException, IOException, InvalidNameException, URISyntaxException {
try {
String altImportUrl = getConfigurationMgr().getAltUrlFromPublicUri(importedModelUri);
OntModel model = getOntModelForEditing(modelName);
Resource importingOntology = model.getOntology(modelName);
if (importingOntology == null) {
importingOntology = model.createResource(modelName);
}
model.getOntology(modelName).addImport(importingOntology);
model.loadImports();
return true;
} catch (ConfigurationException e) {
throw new ConfigurationException("Model cannot be imported as its location is unknown.", e);
}
}
示例2: getOntResourcesOfType
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
* Gets a list of resources of the given type
*
* @param model Jena model
* @param resource Given resource
* @return List of resources
*/
public static List<Resource> getOntResourcesOfType(Model model, Resource resource) {
List<Resource> res = new ArrayList();
OntModel ontModel = ModelFactory.createOntologyModel();
ontModel.add(model);
ontModel.add(coreModel);
// RDFUtils.print(ontModel);
Resource r2 = ontModel.createResource(resource.getURI());
ExtendedIterator it = ontModel.listIndividuals(r2);
while (it.hasNext()) {
Individual ind = (Individual) it.next();
if (ind.isResource()) {
res.add(ind);
}
}
return res;
}
示例3: buscarUsuarioRdf
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public OutputStream buscarUsuarioRdf(Long id, String urlBase){
OutputStream ret = new ByteArrayOutputStream();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.setNsPrefix( "trires", Constantes.ONTO_URI );
Usuario usuario = entityManager.find(Usuario.class, id);
if (usuario != null){
Resource recurso = model.createResource(Constantes.USUARIO_URI + usuario.getId().toString());
recurso.addProperty(RDF.type, VocabularioMembro.RDF_TYPE_CLASS);
recurso.addProperty(VocabularioMembro.ID, usuario.getId().toString());
recurso.addProperty(VocabularioMembro.DESCRICAO, usuario.getDescricao());
recurso.addProperty(VocabularioMembro.EMAIL, usuario.getEmail());
recurso.addProperty(VocabularioMembro.INSTITUICAO, usuario.getInstituicao());
recurso.addProperty(VocabularioMembro.LINK_LATTES, usuario.getLinkLattes());
recurso.addProperty(VocabularioMembro.NOME, usuario.getNome());
}
model.write(ret, "RDF/XML");
model.close();
return ret;
}
示例4: listarTodosRdf
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public OutputStream listarTodosRdf(String urlBase){
OutputStream ret = new ByteArrayOutputStream();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.setNsPrefix( "trires", Constantes.ONTO_URI );
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Usuario> criteriaQuery = criteriaBuilder.createQuery(Usuario.class);
Root<Usuario> from = criteriaQuery.from(Usuario.class);
criteriaQuery.select(from);
List<Usuario> gruposTrabalho = entityManager.createQuery(criteriaQuery).getResultList();
for (Usuario usuario : gruposTrabalho) {
Resource recurso = model.createResource(Constantes.USUARIO_URI + usuario.getId().toString());
recurso.addProperty(RDF.type, VocabularioMembro.RDF_TYPE_CLASS);
recurso.addProperty(VocabularioMembro.ID, usuario.getId().toString());
recurso.addProperty(VocabularioMembro.DESCRICAO, usuario.getDescricao());
recurso.addProperty(VocabularioMembro.EMAIL, usuario.getEmail());
recurso.addProperty(VocabularioMembro.INSTITUICAO, usuario.getInstituicao());
recurso.addProperty(VocabularioMembro.LINK_LATTES, usuario.getLinkLattes());
recurso.addProperty(VocabularioMembro.NOME, usuario.getNome());
}
model.write(ret, "RDF/XML");
model.close();
return ret;
}
示例5: doTestDatatypeRangeValidation
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private void doTestDatatypeRangeValidation(RDFDatatype over12Type, OntModelSpec spec) {
OntModel ont = ModelFactory.createOntologyModel(spec);
String NS = "http://jena.hpl.hp.com/example#";
Resource over12 = ont.createResource( over12Type.getURI() );
DatatypeProperty hasValue = ont.createDatatypeProperty(NS + "hasValue");
hasValue.addRange( over12 );
ont.createResource(NS + "a").addProperty(hasValue, "15", over12Type);
ont.createResource(NS + "b").addProperty(hasValue, "16", over12Type);
ont.createResource(NS + "c").addProperty(hasValue, "10", over12Type);
ValidityReport validity = ont.validate();
assertTrue (! validity.isValid());
Iterator<Report> ritr = validity.getReports();
while (ritr.hasNext()) {
System.out.println("For spec '" + spec + "': " + ritr.next().toString());
}
ont.write(System.out);
// Check culprit reporting
ValidityReport.Report report = (validity.getReports().next());
Triple culprit = (Triple)report.getExtension();
assertEquals(culprit.getSubject().getURI(), NS + "c");
assertEquals(culprit.getPredicate(), hasValue.asNode());
// ont.createTypedLiteral("15", over12Type).getValue();
// ont.createTypedLiteral("16", over12Type).getValue();
// ont.createTypedLiteral("12", over12Type).getValue();
}
示例6: buscarGrupoTrabalhoRdf
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public OutputStream buscarGrupoTrabalhoRdf(Long id, String urlBase){
OutputStream ret = new ByteArrayOutputStream();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.setNsPrefix( "trires", Constantes.ONTO_URI );
GrupoTrabalho grupoTrabalho = entityManager.find(GrupoTrabalho.class, id);
if (grupoTrabalho != null){
Resource recurso = model.createResource(Constantes.GRUPO_TRABALHO_URI + grupoTrabalho.getId().toString());
recurso.addProperty(RDF.type, VocabularioGrupoTrabalho.RDF_TYPE_CLASS);
recurso.addProperty(VocabularioGrupoTrabalho.ID, grupoTrabalho.getId().toString());
if (grupoTrabalho.isAtivo())
recurso.addProperty(VocabularioGrupoTrabalho.ATIVO, "Sim");
else
recurso.addProperty(VocabularioGrupoTrabalho.ATIVO, "N�o");
recurso.addProperty(VocabularioGrupoTrabalho.DATA_HORA_CRIACAO, grupoTrabalho.getDataHoraCriacao().toString());
recurso.addProperty(VocabularioGrupoTrabalho.DESCRICAO, grupoTrabalho.getDescricao());
recurso.addProperty(VocabularioGrupoTrabalho.NOME, grupoTrabalho.getNome());
recurso.addProperty(VocabularioGrupoTrabalho.OBJETIVO, grupoTrabalho.getObjetivo());
recurso.addProperty(VocabularioGrupoTrabalho.PALAVRAS_CHAVE, grupoTrabalho.getPalavrasChave());
Resource recursoLider = model.createResource(Constantes.USUARIO_URI + grupoTrabalho.getUsuarioLider().getId().toString());
recurso.addProperty(VocabularioGrupoTrabalho.LIDER, recursoLider);
for (Usuario membro : grupoTrabalho.getUsuariosMembros()) {
Resource recursoMembro = model.createResource(Constantes.USUARIO_URI + membro.getId().toString());
recurso.addProperty(VocabularioGrupoTrabalho.MEMBRO, recursoMembro);
}
}
model.write(ret, "RDF/XML");
model.close();
return ret;
}
示例7: listarTodosRdf
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public OutputStream listarTodosRdf(String urlBase){
OutputStream ret = new ByteArrayOutputStream();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.setNsPrefix( "trires", Constantes.ONTO_URI );
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<GrupoTrabalho> criteriaQuery = criteriaBuilder.createQuery(GrupoTrabalho.class);
Root<GrupoTrabalho> from = criteriaQuery.from(GrupoTrabalho.class);
criteriaQuery.select(from);
List<GrupoTrabalho> gruposTrabalho = entityManager.createQuery(criteriaQuery).getResultList();
for (GrupoTrabalho grupoTrabalho : gruposTrabalho) {
Resource recurso = model.createResource(Constantes.GRUPO_TRABALHO_URI + grupoTrabalho.getId().toString());
recurso.addProperty(RDF.type, VocabularioGrupoTrabalho.RDF_TYPE_CLASS);
recurso.addProperty(VocabularioGrupoTrabalho.ID, grupoTrabalho.getId().toString());
if (grupoTrabalho.isAtivo())
recurso.addProperty(VocabularioGrupoTrabalho.ATIVO, "Sim");
else
recurso.addProperty(VocabularioGrupoTrabalho.ATIVO, "N�o");
recurso.addProperty(VocabularioGrupoTrabalho.DATA_HORA_CRIACAO, grupoTrabalho.getDataHoraCriacao().toString());
recurso.addProperty(VocabularioGrupoTrabalho.DESCRICAO, grupoTrabalho.getDescricao());
recurso.addProperty(VocabularioGrupoTrabalho.NOME, grupoTrabalho.getNome());
recurso.addProperty(VocabularioGrupoTrabalho.OBJETIVO, grupoTrabalho.getObjetivo());
recurso.addProperty(VocabularioGrupoTrabalho.PALAVRAS_CHAVE, grupoTrabalho.getPalavrasChave());
Resource recursoLider = model.createResource(Constantes.USUARIO_URI + grupoTrabalho.getUsuarioLider().getId().toString());
recurso.addProperty(VocabularioGrupoTrabalho.LIDER, recursoLider);
for (Usuario membro : grupoTrabalho.getUsuariosMembros()) {
Resource recursoMembro = model.createResource(Constantes.USUARIO_URI + membro.getId().toString());
recurso.addProperty(VocabularioGrupoTrabalho.MEMBRO, recursoMembro);
}
}
model.write(ret, "RDF/XML");
model.close();
return ret;
}
示例8: toRdf
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
* Save tags ontology. If it doesn't exists, build it from scratch.
*
* TODO called on EVERY SAVE of the notebook - very inefficient.
*
* @throws MindRaiderException
*/
public void toRdf() throws MindRaiderException {
// build the ontology and save it using RDF custodian
// create ontology using runtime information
// (tag is class and tagged resource is an instance of this class)
// take tag one by one and create statements
OwlOntology tagOntology=new OwlOntology();
OntModel ontology = tagOntology.getOntology();
OntClass tag= ontology.createClass(MindRaiderConstants.MR_OWL_TAG);
OntClass flag = ontology.createClass(MindRaiderConstants.MR_OWL_FLAG);
// properties
ObjectProperty flagPropertyType = ontology.createObjectProperty(MindRaiderConstants.MR_OWL_PROPERTY_FLAG);
flagPropertyType.addRange(flag);
ObjectProperty tagPropertyType = ontology.createObjectProperty(MindRaiderConstants.MR_OWL_PROPERTY_TAG);
tagPropertyType.addRange(tag);
Collection<TagEntry> values = tags.values();
if(values!=null) {
TagEntryImpl[] tagEntries = values.toArray(new TagEntryImpl[0]);
Property tagProperty = ontology.getProperty(MindRaiderConstants.MR_OWL_PROPERTY_TAG);
Property inNotebookProperty = ontology.createProperty(MindRaiderConstants.MR_OWL_PROPERTY_IN_NOTEBOOK);
if(tagEntries!=null && tagEntries.length>0) {
for(TagEntry tagEntry: tagEntries) {
OntClass tagClass = ontology.createClass(tagEntry.getTagUri());
tagClass.addLabel(tagEntry.getTagLabel(), "en");
flag.addSubClass(tagClass);
tag.addSubClass(tagClass);
// include tagged resources - iterate the hashmap
TaggedResourceEntry[] resources = tagEntry.getResources();
if(resources!=null && resources.length>0) {
logger.debug(" Tag entry resources: "+resources.length);
for(TaggedResourceEntry resource: resources) {
Resource conceptResource = ontology.createResource(resource.conceptUri);
// tagged resource is the instance of the class
ontology.add(ontology.createStatement(conceptResource, tagProperty, tagClass));
ontology.add(ontology.createStatement(conceptResource, RDFS.label, ontology.createLiteral(resource.conceptLabel, "en")));
// timestamp and notebook information is not stored - it would just duplicate
// what's stored in notebook/concepts models - this information will be filled
// on concept load - btw this would also cause problems e.g. on refactoring of
// concepts and notebooks
// ... but I will store it anyway :-) concept is addressed in a notebook
Resource notebookResource= ontology.createResource(resource.notebookUri);
ontology.add(ontology.createStatement(
conceptResource,
inNotebookProperty,
notebookResource));
ontology.add(ontology.createStatement(
notebookResource,
RDFS.label,
ontology.createLiteral(resource.notebookLabel, "en")));
}
}
}
}
}
// store the ontology
MindRaider.rdfCustodian.saveOntology(RdfCustodian.FILENAME_TAGS_ONTOLOGY,tagOntology);
}
示例9: loadImportedModel
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Override
public List<ImportMapping> loadImportedModel(Ontology importingOntology, OntModel importingModel,
String publicImportUri, String altImportUrl) throws ConfigurationException {
// if not given the publicImportUri, then we must have the altImportUrl so find the publicImportUri in mapping
if (publicImportUri == null) {
if (altImportUrl == null) {
throw new ConfigurationException("Must have either a public URI or an actual URL to import a model.");
}
publicImportUri = getPublicUriFromActualUrl(altImportUrl);
}
if (importingOntology == null) {
throw new ConfigurationException("Importing ontology is null!");
}
// if not given altImportUrl, then we must have the publicImportUri so find the altImportUrl in mapping
if (altImportUrl == null) {
altImportUrl = getAltUrlFromPublicUri(publicImportUri);
}
String importingOntologyUri = importingOntology.getURI();
if (importingOntologyUri == null) {
throw new ConfigurationException("Importing ontology '" + importingOntology.toString() + "' does not have an ontology declaration.");
}
if (!importingOntologyUri.equals(publicImportUri)) { // don't import to self
// Now load import model (with setCachedModels true so it loads any indirect imports)
// and add all import OntModels to importing mappings
Resource importedOntology = importingModel.createResource(publicImportUri);
importingOntology.addImport(importedOntology);
}
// this.getJenaDocumentMgr().setCacheModels(true);
this.getJenaDocumentMgr().setProcessImports(true);
ReadFailureHandler rfh = this.getJenaDocumentMgr().getReadFailureHandler();
if (rfh instanceof SadlReadFailureHandler) {
((SadlReadFailureHandler)rfh).setSadlConfigMgr(this);
}
getModelGetter().configureToModel(importingModel);
importingModel.loadImports();
if (readError != null) {
String err = readError;
readError = null;
if (importingModel.hasLoadedImport(publicImportUri)) {
// this must be removed or it will prevent correct loading from another project
importingModel.removeLoadedImport(publicImportUri);
}
this.getJenaDocumentMgr().setProcessImports(false);
throw new ConfigurationException(err);
}
this.getJenaDocumentMgr().setProcessImports(false);
List<ImportMapping> map = new ArrayList<ImportMapping>();
Iterator<String> itr = importingModel.listImportedOntologyURIs(true).iterator();
while (itr.hasNext()) {
String impUri = itr.next();
if (impUri.equals(importingOntology.getURI())) {
// don't count ourselves as an import
importingModel.setNsPrefix("", ConfigurationManager.addHashToNonTerminatedNamespace(impUri));
continue;
}
String prefix = importingModel.getNsURIPrefix(ConfigurationManager.addHashToNonTerminatedNamespace(impUri));
if (prefix == null) {
prefix = getGlobalPrefix(impUri);
if (prefix != null) {
importingModel.setNsPrefix(prefix, ConfigurationManager.addHashToNonTerminatedNamespace(impUri));
}
}
OntModel impModel = importingModel.getImportedModel(impUri);
String actImpUrl = getAltUrlFromPublicUri(impUri);
logger.debug("processing importingModel, url = "+actImpUrl);
ImportMapping im = new ImportMapping(impUri, actImpUrl, null);
im.setModel(impModel);
im.setPrefix(prefix);
map.add(im);
}
this.getJenaDocumentMgr().setProcessImports(false);
// this.getJenaDocumentMgr().setCacheModels(false);
return map;
}