com.hp.hpl.jena.ontology.OntClass Java Examples

The following examples show how to use com.hp.hpl.jena.ontology.OntClass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessingUtils.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
public static List<String> getAllClasses ()
{
   List<String>classes = new ArrayList<String>();
   DrbCortexModel model;
   try
   {
      model = DrbCortexModel.getDefaultModel();
   }
   catch (IOException e)
   {
      return classes;
   }
   ExtendedIterator it= model.getCortexModel().getOntModel().listClasses();
   while (it.hasNext())
   {
      OntClass cl = (OntClass)it.next();
      String uri = cl.getURI();
      if (uri!=null)
         classes.add(uri);
   }
   return classes;
}
 
Example #2
Source File: Repository.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
public ValueDomain getValueDomain(String valueDomainID) {
	Resource resource = mdrDatabase.getQueryFactory().getAdministeredItem(
			valueDomainID);
	OntClass res = mdrDatabase.getOntModel().getOntClass(resource.getURI());
	if (res == null) {
		return null;
	}
	ValueDomain vd = null;
	if (res.hasSuperClass(
			mdrDatabase.getVocabulary().EnumeratedValueDomain, false)) {
		vd = new EnumeratedValueDomainImpl(res, mdrDatabase);

	} else {
		vd = new NonEnumeratedValueDomainImpl(res, mdrDatabase);
	}
	return vd;
}
 
Example #3
Source File: ValueDomainImpl.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ConceptualDomainResource getRepresentingConceptualDomainRepresentation() {
	RDFNode representingConceptualDomainRepresentation = getPropertyValue(mdrDatabase
			.getVocabulary().representingConceptualDomainRepresentation);
	OntClass ontClass = representingConceptualDomainRepresentation.as(
			OntResource.class).asClass();

	ConceptualDomainResource conceptualDomainIND = null;
	if (ontClass
			.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedConceptualDomain)) {
		conceptualDomainIND = new EnumeratedConceptualDomainImpl(
				representingConceptualDomainRepresentation.asResource(),
				mdrDatabase);
	}
	if (ontClass
			.hasSuperClass(mdrDatabase.getVocabulary().NonEnumeratedConceptualDomain)) {
		conceptualDomainIND = new NonEnumeratedConceptualDomainImpl(
				representingConceptualDomainRepresentation.asResource(),
				mdrDatabase);
	}
	if (conceptualDomainIND == null) {
		throw new IllegalStateException(
				"Property value should have a valid OntClass.");
	}
	return conceptualDomainIND;
}
 
Example #4
Source File: DataElementConceptImpl.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ObjectClassResource getDataElementConceptObjectClass() {
	RDFNode dataElementConceptObjectClass = getPropertyValue(mdrDatabase
			.getVocabulary().dataElementConceptObjectClass);
	if (dataElementConceptObjectClass == null) {
		logger.debug("DataElemenetConcept does not have an ObjectClass");
		return null;
	}
	OntClass ontClass = dataElementConceptObjectClass.as(OntResource.class)
			.asClass();
	ObjectClassResource objectClassIND = null;
	if (ontClass.hasSuperClass(mdrDatabase.getVocabulary().Concept)) {
		objectClassIND = new ConceptImpl(
				dataElementConceptObjectClass.asResource(), mdrDatabase);
	}
	if (ontClass
			.hasSuperClass(mdrDatabase.getVocabulary().ConceptRelationship)) {
		objectClassIND = new ConceptRelationshipImpl(
				dataElementConceptObjectClass.asResource(), mdrDatabase);
	}
	if (objectClassIND == null) {
		throw new IllegalStateException(
				"Property value should have a valid OntClass.");
	}
	return objectClassIND;
}
 
Example #5
Source File: ConceptImpl.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setParentConcept(ObjectClass parent) {
	if (parent != null) {
		this.addProperty(RDFS.subClassOf, parent.asMDRResource());
	} else {
		ExtendedIterator<OntClass> l = this.listSuperClasses();
		OntClass found = null;
		while (l.hasNext()) {
			OntClass ontClass = l.next();
			if (ontClass.hasSuperClass(mdrDatabase.getVocabulary().Concept)) {
				found = ontClass;
			}
		}
		if (found != null) {
			this.removeProperty(RDFS.subClassOf, found);
		}
	}
}
 
Example #6
Source File: ProcessingUtils.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public static List<String>getSubClass(String URI)
{
   List<String>sub_classes = new ArrayList<String>();
   DrbCortexItemClass cl = DrbCortexItemClass.getCortexItemClassByName(URI);
   ExtendedIterator it = cl.getOntClass().listSubClasses(true);
   while (it.hasNext())
   {
      String ns = ((OntClass)it.next()).getURI();
      if(ns!=null) sub_classes.add(ns);
   }
   return sub_classes;
}
 
Example #7
Source File: MDRDatabase.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given the name of the resource, retrieves the {@link OntClass} from the
 * associated {@link OntModel}. Default and Test {@link OntModel}s must load
 * the ISO11179 ontology upon the start of the application.
 * 
 * @param name
 * @return
 */
public OntClass getClass(String name) {
	OntClass ontClass = ontModel.getOntClass(BASE_URI + name);
	if (ontClass == null) {
		logger.error("Class: {} does not exist in the OntModel", name);
		throw new IllegalStateException(
				"The classes of the ontology should already be loaded into the Model");
	}
	return ontClass;
}
 
Example #8
Source File: ResourceQueryFactory.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
public List<? super ValueMeaningResource> listValueMeningsOfCD(
		String cdURI, int limit, int offset) {
	List<ValueMeaningResource> vmList = new ArrayList<ValueMeaningResource>();
	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_RDFS).append("SELECT DISTINCT ?vm FROM <")
			.append(MDRDatabase.BASE_URI).append("> WHERE {")
			.append("?vm rdfs:subClassOf mdr:ValueMeaning .")
			.append("?vm mdr:valueMeaningIdentifier ?id . ")
			.append("?vm mdr:containedInValueMeaningSet <").append(cdURI)
			.append("> .").append("} ORDER BY ?id LIMIT ").append(limit)
			.append(" OFFSET ").append(offset);
	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());
	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			OntClass res = mdrDatabase.getOntModel().getOntClass(
					qs.getResource("vm").getURI());
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain)) {
				vmList.add(new ValueMeaningImpl(res, mdrDatabase));
			} else {
				vmList.add(new ValueMeaningImpl(res, mdrDatabase));
			}

		}
	} finally {
		qexec.close();
	}

	return vmList;
}
 
Example #9
Source File: ResourceQueryFactory.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
public List<? super ValueDomainResource> getValueDomainsOfConceptualDomain(
		String cdURI) {
	List<ValueDomainResource> vdList = new ArrayList<ValueDomainResource>();
	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_RDFS).append("SELECT ?vd FROM <")
			.append(MDRDatabase.BASE_URI).append("> WHERE {")
			.append("?vdClass rdfs:subClassOf mdr:ValueDomain .")
			.append("?vd rdfs:subClassOf ?vdClass . ")
			.append("?vd mdr:representingConceptualDomainRepresentation <")
			.append(cdURI).append("> .").append("}");
	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());
	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			OntClass res = mdrDatabase.getOntModel().getOntClass(
					qs.getResource("vd").getURI());
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain)) {
				vdList.add(new EnumeratedValueDomainImpl(res, mdrDatabase));
			} else {
				vdList.add(new NonEnumeratedValueDomainImpl(res,
						mdrDatabase));
			}

		}
	} finally {
		qexec.close();
	}

	return vdList;
}
 
Example #10
Source File: Repository.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param cid
 *            Unique ID of the {@link ConceptualDomain} in the
 *            {@link MDRDatabase}
 * @return The {@link ConceptualDomain}
 */
public ConceptualDomain getConceptualDomain(String uniqueID) {
	Resource cdResource = mdrDatabase.getQueryFactory()
			.getAdministeredItem(uniqueID);
	OntClass cd = mdrDatabase.getOntModel()
			.getOntClass(cdResource.getURI());

	if (cd.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedConceptualDomain)) {
		return new EnumeratedConceptualDomainImpl(cd, mdrDatabase);
	} else {
		return new NonEnumeratedConceptualDomainImpl(cd, mdrDatabase);
	}
}
 
Example #11
Source File: ConceptualDomainImpl.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ValueDomain getValueDomain(String valueDomainID) {
	Resource vdResource = mdrDatabase.getQueryFactory()
			.getAdministeredItem(valueDomainID);
	OntClass vd = mdrDatabase.getOntModel()
			.getOntClass(vdResource.getURI());
	if (vd.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain,
			false)) {
		return new EnumeratedValueDomainImpl(vd, mdrDatabase);
	} else {
		return new NonEnumeratedValueDomainImpl(vd, mdrDatabase);
	}
}
 
Example #12
Source File: DataElementConceptImpl.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ConceptualDomainResource getHavingDataElementConceptConceptualDomainRelationship() {
	RDFNode havingDataElementConceptConceptualDomainRelationship = getPropertyValue(mdrDatabase
			.getVocabulary().havingDataElementConceptConceptualDomainRelationship);
	OntClass ontClass = havingDataElementConceptConceptualDomainRelationship
			.as(OntResource.class).asClass();
	ConceptualDomainResource conceptualDomainIND = null;
	if (ontClass
			.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedConceptualDomain)) {
		conceptualDomainIND = new EnumeratedConceptualDomainImpl(
				havingDataElementConceptConceptualDomainRelationship
						.asResource(),
				mdrDatabase);
	}
	if (ontClass
			.hasSuperClass(mdrDatabase.getVocabulary().NonEnumeratedConceptualDomain)) {
		conceptualDomainIND = new NonEnumeratedConceptualDomainImpl(
				havingDataElementConceptConceptualDomainRelationship
						.asResource(),
				mdrDatabase);
	}
	if (conceptualDomainIND == null) {
		throw new IllegalStateException(
				"Property value should have a OntClass");
	}
	return conceptualDomainIND;
}
 
Example #13
Source File: ConceptImpl.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ObjectClass> getSubConcepts() {
	ExtendedIterator<OntClass> l = this.listSubClasses();
	List<ObjectClass> ocList = new ArrayList<ObjectClass>();

	while (l.hasNext()) {
		OntClass res = l.next();
		ocList.add(new ConceptImpl(res, mdrDatabase));
	}

	return ocList;
}
 
Example #14
Source File: ConceptImpl.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ObjectClass getParentConcept() {
	NodeIterator l = this.listPropertyValues(RDFS.subClassOf);

	while (l.hasNext()) {
		RDFNode res = l.nextNode();
		if (res.canAs(OntClass.class)) {
			OntClass ontClass = res.as(OntClass.class);
			if (ontClass.hasSuperClass(mdrDatabase.getVocabulary().Concept)) {
				return new ConceptImpl(res.asResource(), mdrDatabase);
			}
		}
	}
	return null;
}
 
Example #15
Source File: ProcessingUtils.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public static List<String>getSuperClass(String URI)
{
   List<String>super_classes = new ArrayList<String>();
   DrbCortexItemClass cl = DrbCortexItemClass.getCortexItemClassByName(URI);
   ExtendedIterator it = cl.getOntClass().listSuperClasses(true);
   while (it.hasNext())
   {
      String ns = ((OntClass)it.next()).getURI();
      if(ns!=null) super_classes.add(ns);
   }
   return super_classes;
}
 
Example #16
Source File: OntologyGenerator.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public void createObjectProperty(String domainclass, String propertyname,
		String rangeclass,boolean isSubPropertyOfHasGeometry) {
	OntClass dc = m.getOntClass(NS + domainclass);		
	OntClass rc = m.getOntClass(NS + rangeclass);
	if(rc==null){
		createClass(rangeclass);
		rc= m.getOntClass(NS + rangeclass);
	}
	ObjectProperty p = m.createObjectProperty(NS + propertyname);
	p.addDomain(dc);
	p.addRange(rc);
	if(isSubPropertyOfHasGeometry){
		p.addSuperProperty(m.getProperty(OGC + "hasGeometry"));
	}
}
 
Example #17
Source File: OntologyGenerator.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public void createDatatypeProperty(String classname, String propertyname,
		String datatype) {
	OntClass c = m.getOntClass(NS + classname);
	if(c==null){
		createClass(classname);
		c= m.getOntClass(NS + classname);
	}
	DatatypeProperty p = m.createDatatypeProperty(NS + propertyname);
	p.addDomain(c);
	// RDFDatatype dt =
	// TypeMapper.getInstance().getSafeTypeByName(datatype);
	/*Resource dt = selectXSDType(datatype);
	if (dt != null)
		p.addRange(dt);*/
}
 
Example #18
Source File: OntologyGenerator.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public void createGeometryClass(String name) {
	OntClass c = m.createClass(NS + name);
	c.addComment("Automatically generated by GeoTriples (version: "
			+ OntologyGenerator.class.getPackage()
					.getImplementationVersion() + ")", "EN");
	c.addLabel(name, "EN");
	c.addSuperClass(m.getOntClass(OGC + "Geometry"));
}
 
Example #19
Source File: DataElementImpl.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ValueDomainResource getRepresentedByDataElementRepresentation() {
	RDFNode representedByDataElementRepresentation = getPropertyValue(mdrDatabase
			.getVocabulary().representedByDataElementRepresentation);
	OntClass ontClass = representedByDataElementRepresentation.as(
			OntResource.class).asClass();

	ValueDomainResource valueDomainIND = null;
	if (ontClass
			.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain)) {
		valueDomainIND = new EnumeratedValueDomainImpl(
				representedByDataElementRepresentation.asResource(),
				mdrDatabase);
		logger.info("Representer ValueDomain is an EnumeratedValueDomain");
	}
	if (ontClass
			.hasSuperClass(mdrDatabase.getVocabulary().NonEnumeratedValueDomain)) {
		valueDomainIND = new NonEnumeratedValueDomainImpl(
				representedByDataElementRepresentation.asResource(),
				mdrDatabase);
	}
	if (valueDomainIND == null) {
		throw new IllegalStateException(
				"Property value should have a valid OntClass.");
	}
	return valueDomainIND;
}
 
Example #20
Source File: OntologyGenerator.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public void createClass(String name) {
	OntClass c = m.createClass(NS + name);
	c.addComment("Automatically generated by GeoTriples (version: "
			+ OntologyGenerator.class.getPackage()
					.getImplementationVersion() + ")", "EN");
	c.addLabel(name, "EN");
}
 
Example #21
Source File: ScannerFactory.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Retrieve the dhus system supported items for file scanning processing.
 * Is considered supported all classes having
 * <code>http://www.gael.fr/dhus#metadataExtractor</code> property
 * connection.
 * @return the list of supported class names.
 */
public static synchronized String[] getDefaultCortexSupport ()
{
   DrbCortexModel model;
   try
   {
      model = DrbCortexModel.getDefaultModel ();
   }
   catch (IOException e)
   {
      throw new UnsupportedOperationException (
         "Drb cortex not properly initialized.");
   }

   ExtendedIterator it=model.getCortexModel ().getOntModel ().listClasses ();
   List<String>list = new ArrayList<String> ();

   while (it.hasNext ())
   {
      OntClass cl = (OntClass)it.next ();

      OntProperty metadata_extractor_p = cl.getOntModel().getOntProperty(
            "http://www.gael.fr/dhus#support");

      StmtIterator properties = cl.listProperties (metadata_extractor_p);
      while (properties.hasNext ())
      {
         Statement stmt = properties.nextStatement ();
         LOGGER.debug ("Scanner Support Added for " +
            stmt.getSubject ().toString ());
         list.add (stmt.getSubject ().toString ());
      }
   }
   return list.toArray (new String[list.size ()]);
}
 
Example #22
Source File: ResourceQueryFactory.java    From semanticMDR with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 
 * @param contextURI
 * @param limit
 * @param offset
 * @return
 */
public List<? super ConceptualDomainResource> getConceptualDomainsOfContext(
		String contextURI, Integer limit, Integer offset) {
	List<ConceptualDomainResource> cdList = new ArrayList<ConceptualDomainResource>();
	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_RDFS).append("SELECT ?cd FROM <")
			.append(MDRDatabase.BASE_URI).append("> WHERE {")
			.append("?cdClass rdfs:subClassOf mdr:ConceptualDomain .")
			.append("?cd rdfs:subClassOf ?cdClass .")
			.append("?cd mdr:having ?aic .")
			.append("?aic mdr:administeredItemContextContext <")
			.append(contextURI).append("> . }");
	if (limit != null && offset != null) {
		queryString.append(" LIMIT ").append(limit).append(" OFFSET ")
				.append(offset);
	}
	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());
	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			OntClass res = mdrDatabase.getOntModel().getOntClass(
					qs.getResource("cd").getURI());
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedConceptualDomain)) {
				cdList.add(new EnumeratedConceptualDomainImpl(res,
						mdrDatabase));
			} else {
				cdList.add(new NonEnumeratedConceptualDomainImpl(res,
						mdrDatabase));
			}

		}
	} finally {
		qexec.close();
	}

	return cdList;
}
 
Example #23
Source File: OwlReader.java    From EventCoreference with Apache License 2.0 4 votes vote down vote up
static void readOwlFile (String pathToOwlFile) {
        OntModel ontologyModel =
                ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
        ontologyModel.read(pathToOwlFile, "RDF/XML-ABBREV");
       // OntClass myClass = ontologyModel.getOntClass("namespace+className");

        OntClass myClass = ontologyModel.getOntClass(ResourcesUri.nwr+"domain-ontology#Motion");
        System.out.println("myClass.toString() = " + myClass.toString());
        System.out.println("myClass.getSuperClass().toString() = " + myClass.getSuperClass().toString());

        //List list =
              //  namedHierarchyRoots(ontologyModel);


       Iterator i = ontologyModel.listHierarchyRootClasses()
                .filterDrop( new Filter() {
                    public boolean accept( Object o ) {
                        return ((Resource) o).isAnon();
                    }} ); ///get all top nodes and excludes anonymous classes

       // Iterator i = ontologyModel.listHierarchyRootClasses();
        while (i.hasNext()) {
            System.out.println(i.next().toString());
/*            OntClass ontClass = ontologyModel.getOntClass(i.next().toString());
            if (ontClass.hasSubClass()) {

            }*/
        }

        String q = createSparql("event", "<http://www.newsreader-project.eu/domain-ontology#Motion>");
        System.out.println("q = " + q);
        QueryExecution qe = QueryExecutionFactory.create(q,
                ontologyModel);
        for (ResultSet rs = qe.execSelect() ; rs.hasNext() ; ) {
            QuerySolution binding = rs.nextSolution();
            System.out.println("binding = " + binding.toString());
            System.out.println("Event: " + binding.get("event"));
        }

        ontologyModel.close();
    }
 
Example #24
Source File: VirtuosoQueryFactory.java    From semanticMDR with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<? super ValueDomainResource> searchValueDomain(String keyword,
		String uri, TextSearchType searchType) {
	List<ValueDomainResource> vdList = new ArrayList<ValueDomainResource>();
	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_RDFS)
			.append("SELECT ?cd FROM <")
			.append(MDRDatabase.BASE_URI)
			.append("> WHERE {")
			.append("?cdClass rdfs:subClassOf mdr:ValueDomain .")
			.append("?cd rdfs:subClassOf ?cdClass .")
			.append("?cd mdr:having ?aic .")
			.append("?aic mdr:administeredItemContextTerminologicalEntry ?te .")
			.append("?te mdr:containingTerminologicalEntryLanguage ?ls .")
			.append("?ls mdr:containingNameEntry ?designation .")
			.append("?designation mdr:name ?name .");
	if (!Util.isNull(uri)) {
		queryString.append("?aic mdr:administeredItemContextContext <")
				.append(uri).append("> .");
	}
	if (keyword.matches("\\s*")) {
		return vdList;
	}
	if (searchType == null || searchType.equals(TextSearchType.Exact)) {
		queryString.append(exactMatchKeyword(keyword));
	}

	else if (searchType.equals(TextSearchType.WildCard)) {
		queryString.append(atLeastOneKeyword(keyword));
	}

	else {
		queryString.append(allWordsKeyword(keyword));
	}
	queryString.append(" .}");

	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());
	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			Resource tempRes = this.mdrDatabase.getOntModel().getResource(
					qs.getResource("cd").getURI());
			OntClass res = tempRes.as(OntClass.class);
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain)) {
				vdList.add(new EnumeratedValueDomainImpl(res, mdrDatabase));
			} else {
				vdList.add(new NonEnumeratedValueDomainImpl(res,
						mdrDatabase));
			}

		}
	} finally {
		qexec.close();
	}
	return vdList;
}
 
Example #25
Source File: VirtuosoQueryFactory.java    From semanticMDR with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<? super ConceptualDomainResource> searchConceptualDomain(
		String keyword, String contextURI, TextSearchType searchType) {
	List<ConceptualDomainResource> cdList = new ArrayList<ConceptualDomainResource>();
	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_RDFS)
			.append("SELECT ?cd FROM <")
			.append(MDRDatabase.BASE_URI)
			.append("> WHERE {")
			.append("?cdClass rdfs:subClassOf mdr:ConceptualDomain .")
			.append("?cd rdfs:subClassOf ?cdClass .")
			.append("?cd mdr:having ?aic .")
			.append("?aic mdr:administeredItemContextTerminologicalEntry ?te .")
			.append("?te mdr:containingTerminologicalEntryLanguage ?ls .")
			.append("?ls mdr:containingNameEntry ?designation .")
			.append("?designation mdr:name ?name .");
	if (!Util.isNull(contextURI)) {
		queryString.append("?aic mdr:administeredItemContextContext <")
				.append(contextURI).append("> .");
	}
	if (keyword.matches("\\s*")) {
		return cdList;
	}
	if (searchType == null || searchType.equals(TextSearchType.Exact)) {
		queryString.append(exactMatchKeyword(keyword));
	}

	else if (searchType.equals(TextSearchType.WildCard)) {
		queryString.append(atLeastOneKeyword(keyword));
	}

	else {
		queryString.append(allWordsKeyword(keyword));
	}
	queryString.append(" .}");

	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());
	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			Resource tempRes = this.mdrDatabase.getOntModel().getResource(
					qs.getResource("cd").getURI());
			OntClass res = tempRes.as(OntClass.class);
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedConceptualDomain)) {
				cdList.add(new EnumeratedConceptualDomainImpl(res,
						mdrDatabase));
			} else {
				cdList.add(new NonEnumeratedConceptualDomainImpl(res,
						mdrDatabase));
			}

		}
	} finally {
		qexec.close();
	}
	return cdList;
}
 
Example #26
Source File: TDBQueryFactory.java    From semanticMDR with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<? super ValueDomainResource> searchValueDomain(String keyword,
		String contextURI, TextSearchType searchType) {
	List<ValueDomainResource> vdList = new ArrayList<ValueDomainResource>();
	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_PF)
			.append(PREFIX_RDFS)
			.append("SELECT ?cd FROM <")
			.append(MDRDatabase.BASE_URI)
			.append("> WHERE {")
			.append("?cdClass rdfs:subClassOf mdr:ValueDomain .")
			.append("?cd rdfs:subClassOf ?cdClass .")
			.append("?cd mdr:having ?aic .")
			.append("?aic mdr:administeredItemContextTerminologicalEntry ?te .")
			.append("?te mdr:containingTerminologicalEntryLanguage ?ls .")
			.append("?ls mdr:containingNameEntry ?designation .")
			.append("?designation mdr:name ?name .");
	if (!Util.isNull(contextURI)) {
		queryString.append("?aic mdr:administeredItemContextContext <")
				.append(contextURI).append("> .");
	}
	if (keyword.matches("\\s*")) {
		return vdList;
	}
	if (searchType == null || searchType.equals(TextSearchType.Exact)) {
		queryString.append(exactMatchKeyword(keyword));
	}

	else if (searchType.equals(TextSearchType.WildCard)) {
		queryString.append(atLeastOneKeyword(keyword));
	}

	else {
		queryString.append(allWordsKeyword(keyword));
	}
	queryString.append(" .}");

	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());
	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			OntClass res = qs.getResource("cd").as(OntClass.class);
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain)) {
				vdList.add(new EnumeratedValueDomainImpl(res, mdrDatabase));
			} else {
				vdList.add(new NonEnumeratedValueDomainImpl(res,
						mdrDatabase));
			}

		}
	} finally {
		qexec.close();
	}
	return vdList;
}
 
Example #27
Source File: TDBQueryFactory.java    From semanticMDR with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<? super ConceptualDomainResource> searchConceptualDomain(
		String keyword, String contextURI, TextSearchType searchType) {
	List<ConceptualDomainResource> cdList = new ArrayList<ConceptualDomainResource>();
	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_PF)
			.append(PREFIX_RDFS)
			.append("SELECT ?cd FROM <")
			.append(MDRDatabase.BASE_URI)
			.append("> WHERE {")
			.append("?cdClass rdfs:subClassOf mdr:ConceptualDomain .")
			.append("?cd rdfs:subClassOf ?cdClass .")
			.append("?cd mdr:having ?aic .")
			.append("?aic mdr:administeredItemContextTerminologicalEntry ?te .")
			.append("?te mdr:containingTerminologicalEntryLanguage ?ls .")
			.append("?ls mdr:containingNameEntry ?designation .")
			.append("?designation mdr:name ?name .");
	if (!Util.isNull(contextURI)) {
		queryString.append("?aic mdr:administeredItemContextContext <")
				.append(contextURI).append("> .");
	}
	if (keyword.matches("\\s*")) {
		return cdList;
	}
	if (searchType == null || searchType.equals(TextSearchType.Exact)) {
		queryString.append(exactMatchKeyword(keyword));
	}

	else if (searchType.equals(TextSearchType.WildCard)) {
		queryString.append(atLeastOneKeyword(keyword));
	}

	else {
		queryString.append(allWordsKeyword(keyword));
	}
	queryString.append(" .}");

	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());
	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			OntClass res = qs.getResource("cd").as(OntClass.class);
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedConceptualDomain)) {
				cdList.add(new EnumeratedConceptualDomainImpl(res,
						mdrDatabase));
			} else {
				cdList.add(new NonEnumeratedConceptualDomainImpl(res,
						mdrDatabase));
			}

		}
	} finally {
		qexec.close();
	}
	return cdList;
}
 
Example #28
Source File: ResourceQueryFactory.java    From semanticMDR with GNU General Public License v3.0 4 votes vote down vote up
public List<? super ValueDomainResource> getValueDomainsOfContext(
		String contextURI, Integer limit, Integer offset) {
	List<ValueDomainResource> valueDomainResourceList = new ArrayList<ValueDomainResource>();

	StringBuilder queryString = new StringBuilder(PREFIX_MDR)
			.append(PREFIX_RDFS).append("SELECT ?vd FROM <")
			.append(MDRDatabase.BASE_URI).append("> WHERE {")
			.append("?vdClass rdfs:subClassOf mdr:ValueDomain .")
			.append("?vd rdfs:subClassOf mdr:vdClass . ")
			.append("?vd mdr:having ?aic .")
			.append("?aic mdr:administeredItemContextContext <")
			.append(contextURI).append("> .").append("}");
	if (limit != null && offset != null) {
		queryString.append(" ORDER BY ?de ").append(" LIMIT ")
				.append(limit).append(" OFFSET ").append(offset);
	}
	QueryExecution qexec = this.createQueryExecution(
			queryString.toString(), this.mdrDatabase.getOntModel());

	try {
		ResultSet rs = qexec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			// here conceptualDomain is checked whether its enumerated or
			// not, proper instantiation is done
			OntClass res = mdrDatabase.getOntModel().getOntClass(
					qs.getResource("cd").getURI());
			if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain)) {
				valueDomainResourceList.add(new EnumeratedValueDomainImpl(
						res, mdrDatabase));
			} else {
				valueDomainResourceList
						.add(new NonEnumeratedValueDomainImpl(res,
								mdrDatabase));
			}
		}
	} finally {
		qexec.close();
	}
	return valueDomainResourceList;
}
 
Example #29
Source File: OntologyGenerator.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public void addFeatureAsSuperClass(String classname){
	OntClass c = m.getOntClass(NS + classname);
	c.addSuperClass(m.getOntClass(OGC + "Feature"));
}
 
Example #30
Source File: OntologyLoader.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public ExtendedIterator<OntClass> getClasses() {
	return model.listClasses();
}