> This query now display both student and highscore
>
> select ?subject ?student ?highScore where {
> {select ?subject (max(?score) as ?highScore) { ?student ont:Englishsscore
> ?score
>  }
>     group by ?subject
>   }
> ?student ont:Englishscore ?highScore
> }
Doesn't make sense. Don't copy answers from Stackoverflow if the data
doesn't match the suggested solution by Joshua Taylor! You're grouping
by a variable ?subject that is nowhere assigned in the query.

I already gave you the alternative query yesterday in one of my
responses. Would be good if you read them carefully and also try to
understand what's happening there.
>
> On Fri, Jan 6, 2017 at 4:39 PM, javed khan <[email protected]> wrote:
>
>> Hi Lorenz, I uses this
>>
>> SELECT  (max(?score) as ?highScore)
>> WHERE { ?std ont:Englishscore ?score }
>>
>> And it gives me the highscore of subject English as 77
>>
>> When I use this
>>
>> SELECT ?std (max(?score) as ?highScore)
>> WHERE { ?std ont:Englishscore ?score } GROUP BY ?std
>>
>> It gives me all the students with the scores like:
>> Jim 60
>> Kane 77
>> Smith 57 etc
>>
>> I want result like *Kane 77*
>>
>>
>>
>> On Fri, Jan 6, 2017 at 1:45 PM, Lorenz B. <[email protected]
>> leipzig.de> wrote:
>>
>>> Yes, that would be the easiest solution.
>>>
>>>> Hello Lorenz, thanks a lot for kind cooperation.
>>>>
>>>>  It means I will have three queries for NetworkingScore,
>>> Cryptographyscore
>>>> and SEscore?
>>>>
>>>> On Thu, Jan 5, 2017 at 1:27 PM, Lorenz B. <
>>>> [email protected]> wrote:
>>>>
>>>>> The query I showed returns the highest value for one subject as I said.
>>>>> Executing three SPARQL queries should therefore be rather simple.
>>>>>
>>>>> PREFIX ex: <http://example.com/ns/>
>>>>> SELECT (MAX(?score) AS ?topScore)
>>>>> WHERE
>>>>> {
>>>>>   ?student ex:CryptographyScore ?score .
>>>>> }
>>>>>
>>>>> So what's wrong with this query? If you also want to have the
>>> student(s)
>>>>> with this score, try
>>>>>
>>>>> PREFIX ex: <http://example.com/ns/>
>>>>> SELECT ?student ?topScore WHERE {
>>>>>
>>>>>     #-- Find the high score in the subject
>>>>>     {
>>>>>
>>>>>         SELECT (MAX(?score) AS ?topScore) WHERE
>>>>>         {
>>>>>           ?student ex:CryptographyScore ?score .
>>>>>         }
>>>>>
>>>>>     }
>>>>>
>>>>>     #-- Then find the student(s) that had that high score in the
>>> subject
>>>>>     ?student ex:CryptographyScore ?topScore .
>>>>>
>>>>> }
>>>>>
>>>>> Or you can use SPARQL 1.1 aggregate function SAMPLE.
>>>>>
>>>>> Otherwise you can also use a single SPARQL query and put, but it looks
>>>>> like you have to learn SPARQL and we're doing your homework - this is
>>>>> obviously the wrong direction when you want to lean something about
>>>>> Semantic Web...
>>>>>
>>>>> By the way, I wouldn't create a data property for each subject but
>>>>> attach the subject to the score. But that's how I would do it and out
>>> of
>>>>> scope here.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Let me explain : There are 4 students, having scores of three subjects
>>>>>> (1) Bob:  Cryptographyscore 50, SE score 58, *Networking score 70*
>>>>>>  (2) Jim:  *Cryptographyscore 86*, SEscore 55, Networkingscore 48
>>>>>> (3)  Smith: Cryptographyscore 78, *SEscore 79*, Networkingscore 60
>>>>>> (4) David: Cryptographyscore 50, SEscore 66, Networkingscore 55
>>>>>>
>>>>>> I want the highest score of each category any user has scored, like in
>>>>>> cryptography the highest score is 86 scored by Jim, in SE highest
>>> score
>>>>> is
>>>>>> 79 scored by Smith and so on.
>>>>>>
>>>>>> So I want the maximum score in each of the three categories, which are
>>>>> our
>>>>>> data properties in the rdf file and this is why I thought we should
>>> use
>>>>>> three variables for Max.
>>>>>>
>>>>>> Lorenz still I achieve this with the query you and Rob have suggested?
>>>>>>
>>>>>> Thank you
>>>>>>
>>>>>>
>>>>>> On Wed, Jan 4, 2017 at 6:38 PM, Lorenz Buehmann <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>>> Hello Rob,
>>>>>>>>
>>>>>>>> We are in a group and we discussed it.
>>>>>>>>
>>>>>>>> We have three data properties , CryptographyScore,
>>> SoftwareEngineering
>>>>>>>> score and NetworkingScore and we need the maximum of these three
>>> scores
>>>>>>> for
>>>>>>>> a student.
>>>>>>>>
>>>>>>>> Can we do it like this
>>>>>>>>
>>>>>>>> SELECT ?student (MAX(?score1, ?score2, ?score3) AS ?topScore)
>>>>>>>>
>>>>>>> No, Rob almost showed the solution. It's not allowed and I also don't
>>>>>>> see why you want to use 3 variables in the MAX function.
>>>>>>>
>>>>>>> Again, we assume that you want to get the maximum score among all
>>>>>>> students for a particular subject!
>>>>>>>
>>>>>>> That means, the query would be (for CryptographyScore here only)
>>>>>>>
>>>>>>> PREFIX ex: <http://example.com/ns/>
>>>>>>> SELECT (MAX(?score) AS ?topScore)
>>>>>>> WHERE
>>>>>>> {
>>>>>>>   ?student ex:CryptographyScore ?score .
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> You asked the same question on Stackoverflow by the way and I told
>>> you
>>>>>>> there to use SPARQL qith aggregate functions. I assume that you're a
>>>>>>> group of CS students, so you should know about SQL which also
>>> supports
>>>>>>> GROUP BY + aggregate functions. The principle is the same.
>>>>>>>> On Wed, Jan 4, 2017 at 5:05 PM, Rob Vesse <[email protected]>
>>>>> wrote:
>>>>>>>>> Most likely not
>>>>>>>>>
>>>>>>>>> You seem to be running into the XY problem a lot (
>>>>> http://xyproblem.info
>>>>>>> )
>>>>>>>>> You keep asking how to do things with rules for which rules are not
>>>>>>> really
>>>>>>>>> designed. And from some of your responses it sounds like the
>>> problems
>>>>>>>>> you’re trying to solve don’t actually need rules at all.
>>>>>>>>>
>>>>>>>>> For example finding the top score for a student would be much more
>>>>>>> easily
>>>>>>>>> done with a SPARQL query although from what little I have seen of
>>> your
>>>>>>> data
>>>>>>>>> model it looks like it would make it even that quite awkward.  But
>>> in
>>>>>>>>> general terms something like the following would work:
>>>>>>>>>
>>>>>>>>> PREFIX ex: <http://example.com/ns/>
>>>>>>>>> SELECT ?student (MAX(?score) AS ?topScore)
>>>>>>>>> WHERE
>>>>>>>>> {
>>>>>>>>>   ?student ex:score ?score .
>>>>>>>>> }
>>>>>>>>> GROUP BY ?student
>>>>>>>>>
>>>>>>>>> Rob
>>>>>>>>>
>>>>>>>>> On 04/01/2017 13:25, "javed khan" <[email protected]> wrote:
>>>>>>>>>
>>>>>>>>>     Thanks Dave and Lorenz for your response.
>>>>>>>>>
>>>>>>>>>     What if we have entered the score for a student in Cryptography
>>>>> and
>>>>>>>>>     SoftwareEngineering and did not entered for Networking subject
>>> and
>>>>>>>>> stored
>>>>>>>>>     something like this in our owl file:
>>>>>>>>>
>>>>>>>>>     Student1
>>>>>>>>>
>>>>>>>>>      Name: Bob
>>>>>>>>>      CryptographyScore: 60
>>>>>>>>>      SoftwareEngineeringScore: 80
>>>>>>>>>      //NetworkingScore, not mentioned here
>>>>>>>>>
>>>>>>>>>     Then will the above rule fires?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>     On Wed, Jan 4, 2017 at 11:35 AM, Lorenz B. <
>>>>>>>>>     [email protected]> wrote:
>>>>>>>>>
>>>>>>>>>     > Inline comments:
>>>>>>>>>     > > I have three subjects marks for a student.
>>>>>>>>>     > >  Cryptography, Networking, Software Engineering with
>>> different
>>>>>>>>> marks for
>>>>>>>>>     > > each student.
>>>>>>>>>     > > I want to calculate in which subject a student got maximum
>>>>> marks
>>>>>>>>> using
>>>>>>>>>     > Jena
>>>>>>>>>     > > rule and will set that subject as HighScoreSubject of the
>>>>>>> student (
>>>>>>>>>     > > HighScoreSubject is data propety) whose values will be one
>>> of
>>>>>>>>> these three
>>>>>>>>>     > > subjects.
>>>>>>>>>     > >
>>>>>>>>>     > > Is this rule correct to get the required result ( I am
>>> asking
>>>>>>> this
>>>>>>>>>     > because
>>>>>>>>>     > > I am not getting the result required)
>>>>>>>>>     > Without seeing the data, it's always difficult to say if
>>>>>>> something is
>>>>>>>>>     > correct or not. Sample data makes things easier.
>>>>>>>>>     > And without knowing how you apply the rules (in a correct
>>>>> syntax)
>>>>>>>>> it's
>>>>>>>>>     > even harder. That means, it's always good to show the
>>> relevant
>>>>>>> code.
>>>>>>>>>     > >
>>>>>>>>>     > > ?x rdf:type std:Student + ?x std:CryptographyScore ?score1
>>> +
>>>>> ?x
>>>>>>>>>     > > std:NetworkingScore ?score2 + ?x std:SEScore ?score3 +
>>>>>>>>>     > > greaterThan(?score1,?score2), greaterThan(?score1, ?score3)
>>>>> -->
>>>>>>>>>     > > ?x std:HighScoreSubject std:Cryptography
>>>>>>>>>     > >
>>>>>>>>>     > This rule covers only the case when the score for
>>> Cryptography
>>>>> is
>>>>>>> the
>>>>>>>>>     > highest. If your data doesn't contain a student that matches
>>> the
>>>>>>>>> rule,
>>>>>>>>>     > nothing will happen.
>>>>>>>>>     >
>>>>>>>>>     >
>>>>>>>>>     > Cheers,
>>>>>>>>>     > Lorenz
>>>>>>>>>     >
>>>>>>>>>     > --
>>>>>>>>>     > 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
>>>>>
>>>>>
>>> --
>>> 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

Reply via email to