来自GROUP_CONCAT的CONCAT结果

时间:2018-10-19 15:04:01

标签: sparql

我在使用sparql查询时遇到麻烦。我有两个图:学科和教授。 “学科”图包含不同的学科,并感谢他的ID与教授链接。例如,我有:

<http://www.rdcproject.com/graph/disciplines> {
<http://www.rdfproject.com/77803>
        a       <http://www.rdfproject.com/Discipline> ;
        <http://www.rdfproject.com/cfu>
                "6" ;
        <http://www.rdfproject.com/disciplineAbbreviation>
                "SE" ;
        <http://www.rdfproject.com/disciplinename>
                "Software Engineering" ;
        <http://www.rdfproject.com/hasCourseof>
                <http://www.rdfproject.com/8028> ;
        <http://www.rdfproject.com/idDiscipline>
                "77803" ;
        <http://www.rdfproject.com/isTaughtBy>
                <http://www.rdfproject.com/0009004> , 
        <http://www.rdfproject.com/0004003> ;
        <http://www.rdfproject.com/obligatory>
                "false" ;
        <http://www.rdfproject.com/semester>
                "1" ;
        <http://www.rdfproject.com/totalhours>
                "50" ;
        <http://www.rdfproject.com/weekhours>
                "5" ;
        <http://www.rdfproject.com/year>
                "1" .

该课程由两名教授教授:

<http://www.rdfproject.com/0009004>
        a       <http://www.rdfproject.com/Teacher> ;
        <http://www.rdfproject.com/firstName>
                "Koby" ;
        <http://www.rdfproject.com/idProfessor>
                "0009004" ;
        <http://www.rdfproject.com/lastName>
                "Bryant" ;
        <http://www.rdfproject.com/role>
                "contratto" .

<http://www.rdfproject.com/0004003>
        a       <http://www.rdfproject.com/Teacher> ;
        <http://www.rdfproject.com/firstName>
                "Lebron" ;
        <http://www.rdfproject.com/idProfessor>
                "0004003" ;
        <http://www.rdfproject.com/lastName>
                "James" ;
        <http://www.rdfproject.com/role>
                "associato" .

现在,我希望所有学科的所有教授。我创建了以下查询:

PREFIX uni: <http://www.rdfproject.com/>
                PREFIX un: <http://www.w3.org/2007/ont/unit#>

                SELECT  ?idDiscipline ?disciplineName  
                        (CONCAT('[',GROUP_CONCAT(?idProf;separator=","),', ',GROUP_CONCAT(?firstName;separator=","),', ',GROUP_CONCAT(?lastName;separator=","),', ',GROUP_CONCAT(?role;separator=","),']') as ?professors)

                FROM <http://www.rdcproject.com/graph/disciplines>
                FROM <http://www.rdcproject.com/graph/professor>
                WHERE
                { 
                        {       
                        ?x  a uni:Discipline;
                        uni:disciplinename ?disciplineName;
                        uni:idDiscipline ?idDiscipline;
                        uni:disciplineAbbreviation ?sigleDiscipline;
                        uni:cfu ?cfu;
                        uni:hasCourseof ?hasCourseof;
                        uni:obligatory ?obligatory;
                        uni:semester ?semester;
                        uni:totalhours ?totalhours;
                        uni:weekhours ?weekhours;
                        uni:year ?year;
                        uni:isTaughtBy ?isTaughtBy.
                            ?isTaughtBy a uni:Teacher;
                            uni:idProfessor ?idProf;
                            uni:firstName ?firstName;
                            uni:role ?role;
                            uni:lastName ?lastName.
                        }



                }GROUP BY ?idDiscipline ?disciplineName 

此查询工作正常,因为一门学科只包含一名教授,但是在这种情况下,结果是:

ID -> 77803"  
NAME -> "Software Engineering" 
PROFESSOR -> "[0009004,0004003, Kobe,Lebron, Bryant ,James, 
        contract,contract]"

如何获得此结果?

ID -> 77803"  
NAME -> "Software Engineering" 
PROFESSOR -> "[0009004, Kobe, Bryant, contract] 
              [0004003, Lebron,James, contract]

谢谢

编辑: 感谢@AKSW 我的新查询是:

PREFIX uni: <http://www.rdfproject.com/>
            PREFIX un: <http://www.w3.org/2007/ont/unit#>

            SELECT  ?idDiscipline ?sigleDiscipline ?disciplineName ?cfu ?hasCourseof ?obligatory ?semester ?totalhours ?weekhours ?year 
           (GROUP_CONCAT(DISTINCT ?prof_str;separator=",") AS ?Professor)

            FROM <http://www.rdcproject.com/graph/disciplines>
            FROM <http://www.rdcproject.com/graph/professor>
            WHERE
            { 
                    {       
                    ?x  a uni:Discipline;
                    uni:disciplinename ?disciplineName;
                    uni:idDiscipline ?idDiscipline;
                    uni:disciplineAbbreviation ?sigleDiscipline;
                    uni:cfu ?cfu;
                    uni:hasCourseof ?hasCourseof;
                    uni:obligatory ?obligatory;
                    uni:semester ?semester;
                    uni:totalhours ?totalhours;
                    uni:weekhours ?weekhours;
                    uni:year ?year;
                    uni:isTaughtBy ?isTaughtBy.
                        ?isTaughtBy a uni:Teacher;
                        uni:idProfessor ?idProf;
                        uni:firstName ?firstName;
                        uni:lastName ?lastName;
                        uni:role ?role.

                    }

                  BIND(CONCAT('[',?idProf,',',?firstName,',',?lastName,',',?role,']') AS ?prof_str)

            }GROUP BY ?idDiscipline ?sigleDiscipline ?disciplineName ?cfu ?hasCourseof ?obligatory ?semester ?totalhours ?weekhours ?year

0 个答案:

没有答案