how to get individual(s) for given class/individual with given object property using SPARQL - sparql

I have simple ontology called "campus.owl".There is a class called"Lecturer" and which has two sub classes ,RegularLecturer and VisitingLecturer.There is a another class called "Student" which is a sibling class of Lecturer class.
I have created individuals for all the classes.
Student class is joind with Lecture class with "has" object property.
problem
I want to get some Lecturer/VisitingLecturer individuals for given student individual. Could you please help me to get this result! Thanks in advance!
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
PREFIX my: http://www.semanticweb.org/ontologies/2010/5/Ontology1275975684120.owl#
SELECT ?lec WHERE { ?lec..........??? }
any idea..??
Thank in advance!

Something like:
SELECT ?lec WHERE { ?lec a ?lectype.
?lectype <http://www.w3.org/2000/01/rdf-schema#subClassOf> <Lecturer>.
<student> <has> ?lec.}
Should do it.

Related

How can I compose new owl classes from existing ontologies without copying data?

in ontology A I have a class Person with dataproperty
hasName and store some data against it:
<person> hasName "Joe Common" .
and a class Vehicle with a hasVINnr;
<vehicle> hasVINnr "12345" .
In ontology B I have class Parking_ticket and in this
I would like to reference the A:Person and A:Vehicle's dataproperties like:
<parking_ticket> hasVehicleOwner A:<person>.hasName .
<parking_ticket> hasVehicleVIN A:<vehicle>.hasVINnr .
I.e. I want the new class parking_ticket's dataproperties to "linkto" "pointto"
the actual entities data in the ontology A. Like you would do in
assebly lang by storing the addressOf for the storage in the parking ticket
rather than duplicating the data. This means that when <person>.hasName is updated
the <parking_ticket>.hasVehicleOwner data is automatically correct.
Is this possible? How can I avoid duplicating the data in parking_ticket and assoc problems?
When selecting on the parking_ticket I would like to see the values it points
to.

sparql query to get all individual of specific class using data value

I have an ontology that contains two classes (course,lesson) the course has a data properties called code of type string
How to get all individuals from specific class with specific data properties value
here is a screenshot
The general pattern is something like this:
SELECT ?individual
WHERE { ?individual a <uri-of-specific-class> ;
<uri-of-property> ?propertyValue .
FILTER(STR(?propertyValue) = "expected value")
}
You will need to adapt this with the details of your specific ontology (the URIs of your class names and properties), but it shows the general approach. I would also suggest that you try out a SPARQL tutorial, there's several good ones online for you to find.

How do I merge in SPARQL?

I have two tables that I have to merge and I'm not too sure how to go about doing so.
Both tables keep a list of teachers and their teaching subjects. Each has a predicate along the lines of school:teaches and college:instructs, which mean the same thing. My task is to merge the schools together but as far as I am familiar with SPARQL I don't know how to do so?
So far I have
SELECT ?teacher
WHERE {
?teacher school:teaches|college:instructs :courses
}
There is not enough information about your data, but assuming :teaches and :instructs are only used to link teachers with courses, you'll need:
SELECT ?teacher
WHERE {
?teacher school:teaches|college:instructs ?courses .
}
Assuming :courses is the class of courses, and all objects of the triples you want to belong to that class, then you'll need to add this patters as well:
SELECT ?teacher
WHERE {
?teacher school:teaches|college:instructs ?courses .
?courses a :courses .
}

combining datatype and objectype properties OWL

I want to combine the instance (results) associated with two different property types. I can combine them using SPARQL, but I would like to define it the model itself. I am not sure what is the best way to accomplish it. Let me provide you a concrete example.
I have two classes (:book, :tag), an objecttype property (:hasTag), and a datatype property (:hasDescription) with strings.
Instances are defined as:
:book1 a :book .
:semantics a :tag .
:book1 :hasTag :semantics .
:book1 :hasDescription "book about web technology" .
:book1 :hasDescription "good for all level of users" .
:book1 :hasDescription "has examples from biomedical industries" .
There are other classes and properties as well. I would like to get the tag results (semantics) and description results ("book about web technology", "good for all level of users", "has examples from biomedical industries") for book1. Can it be done be defining another property and somehow linking the new property to hasTag and hasDescription ? or is there another/better way?
Also, on a separate note, I am assuming that two instances to a datatype property (as I did in the example) is fine. Please let me know if there are any concerns in this case.

Updating datatype property value base on SWRL rules

Hi i have made an ontology in protege 4.3 for users , suppose 1 of my ontology subclass of class user are:
1-"Interest" , and class "interest" have subclasses: "onlineGaming","onlineMovie","onlineshoping",... and every subclass has individual: everyday,onceAweek,onceAmonth)
and i have 3 datatype property for every user: (internetspeed,internetTraffic,Price)
data gathered based on a questionnaire
i just need to infer from this ontology how important this 3 datatype property factors is for internet users
i need to make some SWRL rules in protege to Infer user interest weight , for example if a user do onlineMovie everyday add a +3 to internetTraffic dataproperty.
user(?u) ^ hasOnlineMovieInterest(?u , everyday)-> add +3 to user(?u,InternetTraffic)
user(?u) ^ hasOnlineGamingInterest(?u , OnceAweek) and hasOnlineMovieInterest(?u , everyday)-> add +2 to user(?u,internetSpeed)
how should i write this properly in SWRL rules?
and my second question is how can i have the value of this 3 datatype property for every user in sparql and save the result?
Thanks for your help
First of all; it is not clear what you are doing / which technology using, etc., please consider clarifying your question. Moreover, the conceptual made you developed doesn't seem sound. Are you sure this is the best way to represent the information you want? For example, why would a UserInterest be a subClassOf User? I think you mean that UserInterest and UserInterestRate are ranges for an object property that connect User to them, i.e., hasInterest rdfs:domain User and hasInterest rdfs:range UserInterest.
Coming to your questions, do you use Protege? If you use it you can implement these SWRL rules using the SWRL tab in Protege.
After you have implemented this correctly, you can simply use some SPARQL query similar to:
select ?user ?r1 ?r2 ?r3 Where {
?user rdf:type yourNamespacePrefix:User.
?user yourNamespacePrefix:rate1 ?r1.
?user yourNamespacePrefix:rate2 ?r2.
?user yourNamespacePrefix:rate3 ?r3.
}