Re: Construct query

2016-10-01 Thread Paul Tyson
On Sat, 2016-10-01 at 03:10 -0700, neha gupta wrote:
> Paul, thank you.
> 
> If I have Student/University ontology and the ontology does not have
> "hasResearch" property can we create like this:
> 
> CONSTRUCT {?s ex:hasResearch ?research}
> WHERE {?s rdf:type ex:Student;ex:hasResearch  "C-SPARQL"}
> 
> to create the property and assign instance to it?

That wouldn't construct any triple because ?research will never be bound
by the WHERE clause. If you ever have a question about what triples will
be constructed, just change the CONSTRUCT {...} to SELECT * and see what
results you get. For every result record, CONSTRUCT will create triples
from the patterns whose variables are bound in the result set.

But now I'm not sure whether you are trying to extend the schema (or
ontology), or just assigning properties to existing subjects.

To add ex:hasResearch into the dataset as an rdf:Property you would just
load some triples like:

ex:hasResearch a rdf:Property;
  rdfs:domain ex:Student;
  rdfs:range [owl:oneOf ("C-SPARQL" "RIF" "SPIN")].

If you want to do any kind of OWL reasoning over your dataset you would
need to add some more statements to associate ex:hasResearch as a data
property of ex:Student.

On the other hand, if you just want to say that all students who are
taking a course called "Intro to SPARQL" will "have
research"="C-SPARQL", that would be like:

CONSTRUCT {?s ex:hasResearch "C-SPARQL"}
WHERE {?s rdf:type ex:Student; ex:hasCourse/rdfs:label "Intro to
SPARQL"}

Regards,
--Paul

> 
> On Fri, Sep 30, 2016 at 8:52 PM, Paul Tyson  wrote:
> 
> > On Thu, 2016-09-29 at 13:44 -0700, tina sani wrote:
> > > I want to know about the Construct query.
> > > How it differs from Select query
> >
> > One way to think about it, if you have any background in relational
> > databases, is that SELECT returns a highly denormalized table (at least,
> > from any non-trivial query). On the other hand, CONSTRUCT will give you
> > an over-normalized set of tables, if you think of each RDF property
> > triple (or quad, if you include graph uri) as an RDBMS table.
> >
> > That is a very abstract view. Syntactically, the results of CONSTRUCT
> > and SELECT are quite different. SELECT must be serialized into something
> > like a table model (csv or the isomorphic xml, json, or text versions).
> > CONSTRUCT results are serialized into some RDF format.
> >
> > > Is it create a new property/class which is not already in the ontology or
> > > it just creates new triples.
> >
> > You can do either (or both). You can use CONSTRUCT to extract a
> > subgraph, or to create new triples based on some rules about the
> > existing data.
> >
> > > I will appreciate if some one come with a simple example. I have searched
> > > web, but could not grasp it.
> >
> > Extract a subgraph. Just get rdf:type and rdfs:label of all subjects.
> > CONSTRUCT {?s rdf:type ?type;rdfs:label ?label}
> > WHERE {?s rdf:type ?type;rdfs:label ?label}
> >
> > Make a new statement based on certain conditions in the dataset.
> > CONSTRUCT {?s :new-property false}
> > WHERE {?s rdf:type ex:TypeA;ex:property1 "A"}
> >
> > Materialize superclass properties:
> > CONSTRUCT {?s rdf:type ?super}
> > WHERE {?s rdf:type ?type;?type rdfs:subClassOf* ?super}
> >
> > As another responder mentioned, CONSTRUCT just returns the triples--it
> > does not modify the dataset. Use a SPARQL update statement
> > (INSERT/WHERE) for that. I've found that with complex or large results
> > it is better in jena to do a CONSTRUCT query and then load the triples
> > into the TDB repository, rather than do an INSERT/WHERE update, which
> > can exhaust resources if the resulting graph is large.
> >
> > Hope this helps.
> >
> > Regards,
> > --Paul
> >
> >




Re: Fetch value from data property

2016-10-01 Thread neha gupta
"You have to get the "wins" value for "team1" first"
This is the basic problem I do not know how to get the int value from
"wins"?

"you first have to get the "team1" individual/resource."
I have individual like this:
 Individual team1 = team.createIndividual(ns + name); //name java variable.

On Sat, Oct 1, 2016 at 8:20 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:

> You have to get the "wins" value for "team1" first, then set the new
> "wins" value for "team1" . That means you first have to get the "team1"
> individual/resource.
>
> RDF data model:
>
> team1 wins 3
>
> team1 = is an individual resp. a resource
> wins = is a data property
> 3 = is a literal value
>
> > I am sorry Lorenz sir,
> > Basically what I want to sum a team wins. When value is entered in text
> > field, it is saved as data property "Wins" value in the file i-e team1
> Wins
> > 3. Since this value 3 is stored in owl file, when another entry is made
> for
> > Wins property, say 2, I want to sum this new value with the previous
> value
> > of Wins property so that it does not stored in the file as:
> > team1 wins 2
> > team1 wins 3
> >
> > *but rather it is stored as:*
> > *team1 wins 5*
> >
> > // variable is java variable having integer value i-e 2
> > *Literal wins=model.createTypedLiteral(variable);*
> > *int win_value=wins.getInt();*
> >
> > *I just want to sum win_value (i-e  2)  with the value in data property
> > "Wins"*
> >
> > OntProperty winsProperty = model.getOntProperty(ns+ "Wins");
> >
> > So without SPARQL, can we get integer value of data property Wins so that
> > we can do
> >
> >  int total_wins= win_value+ (The value from data property Wins).
> >
> > Sorry again for these types of questions, but I am learning Jena course
> my
> > own and I have not studied it in my Bachelor degree (But have to use it
> in
> > my BS project)
> >
> >
> >
> > On Sat, Oct 1, 2016 at 7:07 AM, Lorenz B. <
> > buehm...@informatik.uni-leipzig.de> wrote:
> >
> >> What the hell are you doing here?! Javadoc + Jena documentation is your
> >> friend.
> >>
> >> It does not fetch any data, but creates a property and a literal with
> >> the value that is the property object which is totally wrong.
> >>
> >> First, use proper variable names.
> >>
> >>
> >>> Is this a proper way to fetch the int value from data property?
> >>>
> >>> OntProperty value=model.getOntProperty(ns+ "Wins");
> >> Obviously, this line creates a property object, i.e. call it "property"
> >> or "p" or "winsProperty" or whatever, but not value.
> >>
> >> OntProperty winsProperty = model.getOntProperty(ns+ "Wins");
> >>
> >>
> >>>  Literal myliteral = model.createTypedLiteral(value);
> >> This line creates a Literal object whose value is the property object,
> >> but that's totally wrong. If you want to create an int literal, use an
> >> integer as argument
> >>
> >> Literal myliteral = model.createTypedLiteral(3);
> >>
> >>
> >>
> >>>int sum=myliteral.getInt();
> >> Again weird naming of Java variables which makes the code unreadable and
> >> even more nobody will understand what you want to achieve.
> >> The sum of what?
> >>>sum=sum+1;
> >> It should be clear that data is assigned to RDF resources, that means
> >> you need a resource as well ,that's why the RDF data model is made of
> >> triples (subject, predicate, object), and from the above code you only
> >> have predicate and object.
> >>
> >> --
> >> Lorenz Bühmann
> >> AKSW group, University of Leipzig
> >> Group: http://aksw.org - semantic web research center
> >>
> >>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>


Re: Fetch value from data property

2016-10-01 Thread Lorenz B.
You have to get the "wins" value for "team1" first, then set the new
"wins" value for "team1" . That means you first have to get the "team1"
individual/resource.

RDF data model:

team1 wins 3

team1 = is an individual resp. a resource
wins = is a data property
3 = is a literal value

> I am sorry Lorenz sir,
> Basically what I want to sum a team wins. When value is entered in text
> field, it is saved as data property "Wins" value in the file i-e team1 Wins
> 3. Since this value 3 is stored in owl file, when another entry is made for
> Wins property, say 2, I want to sum this new value with the previous value
> of Wins property so that it does not stored in the file as:
> team1 wins 2
> team1 wins 3
>
> *but rather it is stored as:*
> *team1 wins 5*
>
> // variable is java variable having integer value i-e 2
> *Literal wins=model.createTypedLiteral(variable);*
> *int win_value=wins.getInt();*
>
> *I just want to sum win_value (i-e  2)  with the value in data property
> "Wins"*
>
> OntProperty winsProperty = model.getOntProperty(ns+ "Wins");
>
> So without SPARQL, can we get integer value of data property Wins so that
> we can do
>
>  int total_wins= win_value+ (The value from data property Wins).
>
> Sorry again for these types of questions, but I am learning Jena course my
> own and I have not studied it in my Bachelor degree (But have to use it in
> my BS project)
>
>
>
> On Sat, Oct 1, 2016 at 7:07 AM, Lorenz B. <
> buehm...@informatik.uni-leipzig.de> wrote:
>
>> What the hell are you doing here?! Javadoc + Jena documentation is your
>> friend.
>>
>> It does not fetch any data, but creates a property and a literal with
>> the value that is the property object which is totally wrong.
>>
>> First, use proper variable names.
>>
>>
>>> Is this a proper way to fetch the int value from data property?
>>>
>>> OntProperty value=model.getOntProperty(ns+ "Wins");
>> Obviously, this line creates a property object, i.e. call it "property"
>> or "p" or "winsProperty" or whatever, but not value.
>>
>> OntProperty winsProperty = model.getOntProperty(ns+ "Wins");
>>
>>
>>>  Literal myliteral = model.createTypedLiteral(value);
>> This line creates a Literal object whose value is the property object,
>> but that's totally wrong. If you want to create an int literal, use an
>> integer as argument
>>
>> Literal myliteral = model.createTypedLiteral(3);
>>
>>
>>
>>>int sum=myliteral.getInt();
>> Again weird naming of Java variables which makes the code unreadable and
>> even more nobody will understand what you want to achieve.
>> The sum of what?
>>>sum=sum+1;
>> It should be clear that data is assigned to RDF resources, that means
>> you need a resource as well ,that's why the RDF data model is made of
>> triples (subject, predicate, object), and from the above code you only
>> have predicate and object.
>>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center



Re: Fetch value from data property

2016-10-01 Thread neha gupta
I am sorry Lorenz sir,
Basically what I want to sum a team wins. When value is entered in text
field, it is saved as data property "Wins" value in the file i-e team1 Wins
3. Since this value 3 is stored in owl file, when another entry is made for
Wins property, say 2, I want to sum this new value with the previous value
of Wins property so that it does not stored in the file as:
team1 wins 2
team1 wins 3

*but rather it is stored as:*
*team1 wins 5*

// variable is java variable having integer value i-e 2
*Literal wins=model.createTypedLiteral(variable);*
*int win_value=wins.getInt();*

*I just want to sum win_value (i-e  2)  with the value in data property
"Wins"*

OntProperty winsProperty = model.getOntProperty(ns+ "Wins");

So without SPARQL, can we get integer value of data property Wins so that
we can do

 int total_wins= win_value+ (The value from data property Wins).

Sorry again for these types of questions, but I am learning Jena course my
own and I have not studied it in my Bachelor degree (But have to use it in
my BS project)



On Sat, Oct 1, 2016 at 7:07 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:

> What the hell are you doing here?! Javadoc + Jena documentation is your
> friend.
>
> It does not fetch any data, but creates a property and a literal with
> the value that is the property object which is totally wrong.
>
> First, use proper variable names.
>
>
> > Is this a proper way to fetch the int value from data property?
> >
> > OntProperty value=model.getOntProperty(ns+ "Wins");
> Obviously, this line creates a property object, i.e. call it "property"
> or "p" or "winsProperty" or whatever, but not value.
>
> OntProperty winsProperty = model.getOntProperty(ns+ "Wins");
>
>
> >
> >  Literal myliteral = model.createTypedLiteral(value);
> This line creates a Literal object whose value is the property object,
> but that's totally wrong. If you want to create an int literal, use an
> integer as argument
>
> Literal myliteral = model.createTypedLiteral(3);
>
>
>
> >
> >int sum=myliteral.getInt();
> Again weird naming of Java variables which makes the code unreadable and
> even more nobody will understand what you want to achieve.
> The sum of what?
> >sum=sum+1;
>
> It should be clear that data is assigned to RDF resources, that means
> you need a resource as well ,that's why the RDF data model is made of
> triples (subject, predicate, object), and from the above code you only
> have predicate and object.
>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>


Re: Fetch value from data property

2016-10-01 Thread Lorenz B.
What the hell are you doing here?! Javadoc + Jena documentation is your
friend.

It does not fetch any data, but creates a property and a literal with
the value that is the property object which is totally wrong.

First, use proper variable names.


> Is this a proper way to fetch the int value from data property?
>
> OntProperty value=model.getOntProperty(ns+ "Wins");
Obviously, this line creates a property object, i.e. call it "property"
or "p" or "winsProperty" or whatever, but not value.

OntProperty winsProperty = model.getOntProperty(ns+ "Wins");


>
>  Literal myliteral = model.createTypedLiteral(value);
This line creates a Literal object whose value is the property object,
but that's totally wrong. If you want to create an int literal, use an
integer as argument

Literal myliteral = model.createTypedLiteral(3);



>
>int sum=myliteral.getInt();
Again weird naming of Java variables which makes the code unreadable and
even more nobody will understand what you want to achieve.
The sum of what?
>sum=sum+1;

It should be clear that data is assigned to RDF resources, that means
you need a resource as well ,that's why the RDF data model is made of
triples (subject, predicate, object), and from the above code you only
have predicate and object.

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center



Fetch value from data property

2016-10-01 Thread neha gupta
Is this a proper way to fetch the int value from data property?

OntProperty value=model.getOntProperty(ns+ "Wins");

 Literal myliteral = model.createTypedLiteral(value);

   int sum=myliteral.getInt();
   sum=sum+1;


Re: Construct query

2016-10-01 Thread neha gupta
Actually I have the same query like Tina, but can you explain it in term of
a Student ontology because I understand the Student ontology more.

Like Student hasCourse ?course.
Teacher teaches ?course

On Sat, Oct 1, 2016 at 3:10 AM, neha gupta  wrote:

> Paul, thank you.
>
> If I have Student/University ontology and the ontology does not have
> "hasResearch" property can we create like this:
>
> CONSTRUCT {?s ex:hasResearch ?research}
> WHERE {?s rdf:type ex:Student;ex:hasResearch  "C-SPARQL"}
>
> to create the property and assign instance to it?
>
> On Fri, Sep 30, 2016 at 8:52 PM, Paul Tyson  wrote:
>
>> On Thu, 2016-09-29 at 13:44 -0700, tina sani wrote:
>> > I want to know about the Construct query.
>> > How it differs from Select query
>>
>> One way to think about it, if you have any background in relational
>> databases, is that SELECT returns a highly denormalized table (at least,
>> from any non-trivial query). On the other hand, CONSTRUCT will give you
>> an over-normalized set of tables, if you think of each RDF property
>> triple (or quad, if you include graph uri) as an RDBMS table.
>>
>> That is a very abstract view. Syntactically, the results of CONSTRUCT
>> and SELECT are quite different. SELECT must be serialized into something
>> like a table model (csv or the isomorphic xml, json, or text versions).
>> CONSTRUCT results are serialized into some RDF format.
>>
>> > Is it create a new property/class which is not already in the ontology
>> or
>> > it just creates new triples.
>>
>> You can do either (or both). You can use CONSTRUCT to extract a
>> subgraph, or to create new triples based on some rules about the
>> existing data.
>>
>> > I will appreciate if some one come with a simple example. I have
>> searched
>> > web, but could not grasp it.
>>
>> Extract a subgraph. Just get rdf:type and rdfs:label of all subjects.
>> CONSTRUCT {?s rdf:type ?type;rdfs:label ?label}
>> WHERE {?s rdf:type ?type;rdfs:label ?label}
>>
>> Make a new statement based on certain conditions in the dataset.
>> CONSTRUCT {?s :new-property false}
>> WHERE {?s rdf:type ex:TypeA;ex:property1 "A"}
>>
>> Materialize superclass properties:
>> CONSTRUCT {?s rdf:type ?super}
>> WHERE {?s rdf:type ?type;?type rdfs:subClassOf* ?super}
>>
>> As another responder mentioned, CONSTRUCT just returns the triples--it
>> does not modify the dataset. Use a SPARQL update statement
>> (INSERT/WHERE) for that. I've found that with complex or large results
>> it is better in jena to do a CONSTRUCT query and then load the triples
>> into the TDB repository, rather than do an INSERT/WHERE update, which
>> can exhaust resources if the resulting graph is large.
>>
>> Hope this helps.
>>
>> Regards,
>> --Paul
>>
>>
>


Re: Construct query

2016-10-01 Thread neha gupta
Paul, thank you.

If I have Student/University ontology and the ontology does not have
"hasResearch" property can we create like this:

CONSTRUCT {?s ex:hasResearch ?research}
WHERE {?s rdf:type ex:Student;ex:hasResearch  "C-SPARQL"}

to create the property and assign instance to it?

On Fri, Sep 30, 2016 at 8:52 PM, Paul Tyson  wrote:

> On Thu, 2016-09-29 at 13:44 -0700, tina sani wrote:
> > I want to know about the Construct query.
> > How it differs from Select query
>
> One way to think about it, if you have any background in relational
> databases, is that SELECT returns a highly denormalized table (at least,
> from any non-trivial query). On the other hand, CONSTRUCT will give you
> an over-normalized set of tables, if you think of each RDF property
> triple (or quad, if you include graph uri) as an RDBMS table.
>
> That is a very abstract view. Syntactically, the results of CONSTRUCT
> and SELECT are quite different. SELECT must be serialized into something
> like a table model (csv or the isomorphic xml, json, or text versions).
> CONSTRUCT results are serialized into some RDF format.
>
> > Is it create a new property/class which is not already in the ontology or
> > it just creates new triples.
>
> You can do either (or both). You can use CONSTRUCT to extract a
> subgraph, or to create new triples based on some rules about the
> existing data.
>
> > I will appreciate if some one come with a simple example. I have searched
> > web, but could not grasp it.
>
> Extract a subgraph. Just get rdf:type and rdfs:label of all subjects.
> CONSTRUCT {?s rdf:type ?type;rdfs:label ?label}
> WHERE {?s rdf:type ?type;rdfs:label ?label}
>
> Make a new statement based on certain conditions in the dataset.
> CONSTRUCT {?s :new-property false}
> WHERE {?s rdf:type ex:TypeA;ex:property1 "A"}
>
> Materialize superclass properties:
> CONSTRUCT {?s rdf:type ?super}
> WHERE {?s rdf:type ?type;?type rdfs:subClassOf* ?super}
>
> As another responder mentioned, CONSTRUCT just returns the triples--it
> does not modify the dataset. Use a SPARQL update statement
> (INSERT/WHERE) for that. I've found that with complex or large results
> it is better in jena to do a CONSTRUCT query and then load the triples
> into the TDB repository, rather than do an INSERT/WHERE update, which
> can exhaust resources if the resulting graph is large.
>
> Hope this helps.
>
> Regards,
> --Paul
>
>