Ejemplo n.º 1
0
    def get_is_required_of(cls, discipline_uri):
        """
        Get required that the disciplines is required from triple store.
        """

        query = """
            PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?is_required_of_uri ?is_required_of
            WHERE {
              <%s> pp:isRequiredOf ?is_required_of_uri .
              ?is_required_of_uri dc:title ?is_required_of
            }
        """ % (discipline_uri)

        result = Query.run(Sesame.endpoint, query)

        disciplines = []
        for discipline in result:
            discipline = Discipline(
                title=discipline['is_required_of']['value'],
                uri=discipline['is_required_of_uri']['value'])
            disciplines.append(discipline)

        return disciplines
Ejemplo n.º 2
0
    def get_information(self):
        """
        Get all information about software engineering ontology
        """

        query = """
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
            PREFIX owl: <http://www.w3.org/2002/07/owl#>
            PREFIX es: <http://www.semanticweb.org/ontologies/2018/Software_Engineering/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title ?version ?creator ?habilitation ?source ?performance ?professional_profile
            ?description ?goals ?label
            WHERE {
              ?course dc:title "Software Engineering Course"@en ;
              dc:title ?title ;
              owl:versionInfo ?version ;
              dc:creator ?creator ;
              es:habilitation ?habilitation ;
              dc:source ?source ;
              es:performance ?performance ;
              es:professional_profile ?professional_profile ;
              dc:description ?description ;
              es:goals ?goals ;
              rdfs:label ?label
            }
        """

        result = Query.run(Sesame.endpoint, query)

        return result[0]
    def get_knowledges(self):
        """
        Get the knowledges from triple store.
        """

        query = """
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
            PREFIX owl: <http://www.w3.org/2002/07/owl#>
            PREFIX es: <http://www.semanticweb.org/ontologies/2018/Software_Engineering/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title
            WHERE {
              es:Core_Professional_Content rdfs:subClassOf ?restriction .
              ?restriction owl:onProperty es:hasKnowledgeArea .
              ?restriction owl:someValuesFrom ?knowledges .
              ?knowledges dc:title ?title
            }
        """

        result = Query.run(Sesame.endpoint, query)

        knowledges = []
        for knowledge in result:
            knowledges.append(knowledge['title']['value'])

        return knowledges
Ejemplo n.º 4
0
    def get_knowledges(self):
        """
        Get all knowledges area.
        """

        query = """
            PREFIX knowledge: <http://www.semanticweb.org/ontologies/2018/Knowledge/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?knowledge ?title ?description
            WHERE {
              ?knowledge rdfs:subClassOf knowledge:Knowledge_Area .
              ?knowledge dc:title ?title .
              ?knowledge dc:description ?description
            }
        """

        results = Query.run(Sesame.endpoint, query)

        knowledges = []
        for result in results:
            knowledge = Knowledge(uri=result['knowledge']['value'],
                                  title=result['title']['value'],
                                  description=result['description']['value'])
            knowledges.append(knowledge)

        return knowledges
Ejemplo n.º 5
0
    def get_requireds(cls, discipline_uri):
        """
        Get required disciplines from triple store.
        """

        query = """
            PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?required_uri ?required
            WHERE {
              <%s> pp:hasRequired ?required_uri .
              ?required_uri dc:title ?required
            }
        """ % (discipline_uri)

        result = Query.run(Sesame.endpoint, query)

        disciplines = []
        for discipline in result:
            discipline = Discipline(uri=discipline['required_uri']['value'],
                                    title=discipline['required']['value'])
            disciplines.append(discipline)

        return disciplines
Ejemplo n.º 6
0
    def get_topics(self):
        """
        Get all topics of specific knowledge.
        """

        query = """
            PREFIX knowledge: <http://www.semanticweb.org/ontologies/2018/Knowledge/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?topic ?title ?description
            WHERE {
              ?topic rdfs:subClassOf <%s> .
              ?topic dc:title ?title .
              ?topic dc:description ?description .
            }
        """ % self.uri

        results = Query.run(Sesame.endpoint, query)

        topics = []
        for result in results:
            topic = Topic(uri=result['topic']['value'],
                          title=result['title']['value'],
                          description=result['description']['value'],
                          knowledge=self)
            topics.append(topic)

        return topics
Ejemplo n.º 7
0
def query_do():
    q = Query(session, settings.URLS['query'], stations,
              settings.QUERY_ARGS_NS, settings.TRAIN_DATA_JSON_KEY)
    i = 0
    while True:
        trains = q.query_once(config.FROM_STATION, config.TO_STATION,
                              settings.PURPOSE_CODES[config.TYPE],
                              config.TRAIN_DATE[i], i)
        if trains:
            filtered = q.filter(
                trains, config.TRAINS, settings.SEAT_CODES.values(),
                map(lambda s: settings.SEAT_CODES[s], config.SEATS))
            if filtered:
                print '\x07'
            print map(
                lambda t: '%s %s %s' % (t[settings.TRAIN_DATA_JSON_KEY][
                    'station_train_code'], t['date'], t['seat_type']),
                filtered)
            i = (i + 1) % len(config.TRAIN_DATE)
        time.sleep(settings.QUERY_INTERVAL)
Ejemplo n.º 8
0
    def post(self, request, *args, **kwargs):
        """
        Get the query and return the JSON result
        """

        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        result = Query.run(
            serializer.data['endpoint'],
            serializer.data['query']
        )

        return Response(result, status=status.HTTP_200_OK)
Ejemplo n.º 9
0
    def get_information(self):
        """
        Get the information from triple store
        """

        query = """
            PREFIX es: <http://www.semanticweb.org/ontologies/2018/Software_Engineering/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title
            WHERE {
              es:Basic_Concept_of_a_System dc:title ?title
            }
        """

        result = Query.run(Sesame.endpoint, query)

        return result[0]
Ejemplo n.º 10
0
    def get_information(self):
        """
        Get the data from triple store.
        """

        query = """
            PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title ?description
            WHERE {
              pp:Extension_Activities dc:title ?title ;
              dc:description ?description
            }
        """

        result = Query.run(Sesame.endpoint, query)

        return result[0]
    def get_information(self):
        """
        Get the data from triple store.
        """

        query = """
            PREFIX es: <http://www.semanticweb.org/ontologies/2018/Software_Engineering/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title ?description
            WHERE {
              es:Activities_of_Social_Action_Citizenship_and_Environment dc:title ?title ;
              dc:description ?description
            }
        """

        result = Query.run(Sesame.endpoint, query)

        return result[0]
Ejemplo n.º 12
0
    def get_information(self):
        """
        Get the data from triple store
        """

        query = """
            PREFIX es: <http://www.semanticweb.org/ontologies/2018/Software_Engineering/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title ?description
            WHERE {
              es:Alternate_Abstractions dc:title ?title ;
              dc:description ?description
            }
        """

        result = Query.run(Sesame.endpoint, query)

        return result[0]
Ejemplo n.º 13
0
    def get_information(self):
        """
        Get all information about software engineering ontology
        """

        query = """
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
            PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title ?description
            WHERE {
              pp:Software_Engineering dc:title ?title ;
              dc:description ?description
            }
        """

        result = Query.run(Sesame.endpoint, query)

        return result[0]
Ejemplo n.º 14
0
    def get_information(self):
        """
        Get the information from triple store
        """

        query = """
            PREFIX es: <http://www.semanticweb.org/ontologies/2018/Software_Engineering/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title ?curriculum
            WHERE {
              es:Computing_Foundations dc:title ?title .
              es:Computing_Foundations rdfs:subClassOf ?restriction .
              ?restriction owl:onProperty es:isKnowledgeAreaOf .
              ?restriction owl:someValuesFrom ?curriculum_url .
              ?curriculum_url dc:title ?curriculum
            }
        """

        result = Query.run(Sesame.endpoint, query)

        return result[0]
Ejemplo n.º 15
0
    def get_disciplines(self, predicate, obj):
        """
        Get the data from triple store.
        """

        query = """
            PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?disciplines ?code ?title ?description ?type ?semester ?core_content
            WHERE {
              ?disciplines %s %s .
              ?disciplines dc:title ?title .
              OPTIONAL {?disciplines dc:description ?description .}
              OPTIONAL {?disciplines pp:code ?code .}
              OPTIONAL {?disciplines pp:hasType ?type_uri .}
              OPTIONAL {?type_uri dc:title ?type .}
              OPTIONAL {?disciplines pp:isInTheFlowOf ?semester_uri .}
              OPTIONAL {?semester_uri dc:title ?semester .}
              OPTIONAL {?disciplines pp:isPartOf ?core_content_uri}
              OPTIONAL {?core_content_uri dc:title ?core_content}
            }
        """ % (predicate, obj)

        result = Query.run(Sesame.endpoint, query)

        disciplines = []
        for discipline in result:
            obj = Discipline(uri=discipline['disciplines']['value'],
                             title=discipline['title']['value'],
                             code=discipline['code']['value'],
                             description=discipline['description']['value'],
                             classification=discipline['type']['value'],
                             semester=discipline['semester']['value'],
                             core_content=discipline['core_content']['value'])
            disciplines.append(obj)

        return disciplines
Ejemplo n.º 16
0
    def get_contents(cls, discipline_uri):
        """
        Get content disciplines from triple store.
        """

        query = """
            PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?content_uri ?title
            ?topic_uri ?topic
            ?knowledge_uri ?knowledge
            WHERE {
              <%s> pp:hasContent ?content_uri .
              ?content_uri dc:title ?title .
              ?content_uri rdfs:subClassOf ?topic_uri .
              ?topic_uri dc:title ?topic .
              ?topic_uri rdfs:subClassOf ?knowledge_uri .
              ?knowledge_uri dc:title ?knowledge
            }
        """ % (discipline_uri)

        result = Query.run(Sesame.endpoint, query)

        contents = []
        for content in result:
            knowledge = Knowledge(uri=content['knowledge_uri']['value'],
                                  title=content['knowledge']['value'])
            topic = Topic(uri=content['topic_uri']['value'],
                          title=content['topic']['value'])
            subtopic = Subtopic(uri=content['content_uri']['value'],
                                title=content['title']['value'],
                                topic=topic,
                                knowledge=knowledge)
            contents.append(subtopic)

        return contents
Ejemplo n.º 17
0
    def get_disciplines(self):
        """
        Get all discipline of multidisciplinary content.
        """

        query = """
            PREFIX pp: <http://www.semanticweb.org/ontologies/2018/Pedagogical_Project/>
            PREFIX dc: <http://purl.org/dc/elements/1.1/>

            SELECT DISTINCT ?title
            WHERE {
              ?disciplines pp:isPartOf pp:Multidisciplinary ;
              dc:title ?title
            }
        """

        result = Query.run(Sesame.endpoint, query)

        disciplines = []
        for discipline in result:
            discipline = Discipline(discipline['title']['value'])
            disciplines.append(discipline)

        return disciplines
Ejemplo n.º 18
0
    SELECT DISTINCT ?resumo
    WHERE {
        dbr:Software_engineering dbo:abstract ?resumo
        FILTER (lang(?resumo) = 'pt')
    }
"""

query_unb = """
    SELECT DISTINCT ?sigla ?nome ?cidade ?pais ?estado ?site ?resumo
    WHERE {
        dbr:University_of_Brasília dbp:sigla ?sigla ;
        rdfs:label ?nome ;
        foaf:homepage ?site ;
        dbo:abstract ?resumo ;
        dbo:city ?city .
        ?city rdfs:label ?cidade .
        dbr:University_of_Brasília dbo:country ?country .
        ?country rdfs:label ?pais .
        dbr:University_of_Brasília dbo:state ?state .
        ?state rdfs:label ?estado .

        FILTER (lang(?resumo) = 'pt')
        FILTER (lang(?cidade) = 'pt')
        FILTER (lang(?pais) = 'pt')
        FILTER (lang(?estado) = 'pt')
        FILTER (lang(?nome) = 'pt')
    }
"""

print(Query.run("http://dbpedia.org/sparql", query_unb))