Пример #1
0
def session(request,department_Name,session_Start):
    dep = get_object_or_404(Department, Name=department_Name)
    session = get_object_or_404(Session, Start=session_Start, Department= dep)
    rdfextras.registerplugins()
    g=rdflib.Graph()
    g.parse(session.Student_file)
    g.parse(dep.Professor_file)
    res1 = g.query("""
    PREFIX nit: <http://nitdgp.ac.in/>

    SELECT ?fname ?lname ?email ?roll ?dept ?regno ?address ?prof_fname ?prof_lname ?bgroup ?height ?weight
    WHERE {
            ?x nit:fname ?fname.
            ?x nit:lname ?lname.
            ?x nit:email ?email.
            ?x nit:roll ?roll.
            ?x nit:dept ?dept.
            ?x nit:regno ?regno.
            ?x nit:address ?address.
            ?x nit:email ?email.
            ?x nit:researchUnder ?researchUnder.
            ?x nit:bgroup ?bgroup.
            ?x nit:height ?height.
            ?x nit:weight ?weight.
            ?researchUnder nit:fname ?prof_fname.
            ?researchUnder nit:lname ?prof_lname
        }
    """)
    context = { 'dep' : dep,
                'res1' : res1,
                'session' : session,
     }
    return render(request, 'department/session.html', context)
Пример #2
0
 def __init__(self, filename="../querys/ontology.rdf"):
     self.window = interface.Ui_GamesOntology(self)
     self.window.show()  
       
     rdfextras.registerplugins()
     self.g = rdflib.Graph()
     self.g.parse("../querys/ontology.rdf")
     self.listapergunta = ['','Quem sao os jogadores de uma determinada partida?','Quais sao as regras de determinado jogo?',
     'Quais sao os jogos competitivos?','Quais sao os aparatos para se jogar determinado jogo?',
     'Qual o tipo de um determinado jogo?','Qual o numero de jogadores de determinada partida?','Quais os objetivos de um determinado jogo?',
     'Qual o vencedor de determinada partida?','Quem venceu mais partidas?','Quais as partidas de um determinado jogo?']
     
     self.model = Games_Model()
Пример #3
0
def display(request):
    dept_P = request.GET['dept']
    session_P = request.GET['session']
    regno_P = request.GET['regno']
    sem_P = request.GET['sem']

    dep = get_object_or_404(Department, Name=dept_P)
    session = get_object_or_404(Session, Start=session_P, Department= dep)
    result = get_object_or_404(Result, Session=session, Department=dep, Semester=sem_P)

    rdfextras.registerplugins()
    g=rdflib.Graph()
    g.parse(result.Result_file)
    S = """
    PREFIX nit: <http://nitdgp.ac.in/>

    SELECT ?fname ?lname ?roll ?regno ?cgpa ?sgpa ?BT501LG ?BT502LG ?BT503LG ?OELG ?BT551LG ?BT552LG ?CH581LG
    WHERE {
            ?x nit:fname ?fname.
            ?x nit:lname ?lname.
            ?x nit:regno """+"'"+regno_P+"'"+""".
            ?x nit:roll ?roll.
            ?x nit:regno ?regno.
            ?x nit:cgpa ?cgpa.
            ?x nit:sgpa ?sgpa.
            ?x nit:BT501LG ?BT501LG.
            ?x nit:BT502LG ?BT502LG.
            ?x nit:BT503LG ?BT503LG.
            ?x nit:OELG ?OELG.
            ?x nit:BT551LG ?BT551LG.
            ?x nit:BT552LG ?BT552LG.
            ?x nit:CH581LG ?CH581LG
        }
    """
    res1 = g.query(S)

    context = { 'dep' : dep,
                'res1' : res1,
                'session' : session,
                'sem' : sem_P,
     }

    return render(request, 'department/display.html',context)
Пример #4
0
def detail(request, department_Name):
    dep = get_object_or_404(Department, Name=department_Name)
    sessions = dep.session_set.all()
    rdfextras.registerplugins()
    g=rdflib.Graph()
    g.parse(dep.Professor_file)
    res1 = g.query("""
    PREFIX nit: <http://nitdgp.ac.in/>

    SELECT ?fname ?lname ?email ?research ?designation
    WHERE {
            ?x nit:fname ?fname.
			?x nit:lname ?lname.
            ?x nit:email ?email.
            ?x nit:designation ?designation.
            ?x nit:research ?research
        }
    """)

    context = { 'dep' : dep,
                'res1' : res1,
                'sessions' : sessions,
     }
    return render(request, 'department/detail.html', context)
Пример #5
0
	def __init__(self, filename):
		self.filename = filename
		rdfextras.registerplugins()
		self.g = rdflib.Graph()
		self.g.parse(filename)
Пример #6
0
    RDF_VER=3.0
    # rdflib_sparql seems broken with initNs?

    try:
        plugin.register('sparql', query.Processor,
                       'rdfextras.sparql.processor', 'Processor')
        plugin.register('sparql', query.Result,
                       'rdfextras.sparql.query', 'SPARQLQueryResult')
    except:
        pass


try:
    import rdfextras
    rdfextras.registerplugins()
except:
    pass

import uuid
import time

def now():
    return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())

def gen_uuid():
    return "urn:uuid:%s" % uuid.uuid4()

namespaces = {'ore' : Namespace('http://www.openarchives.org/ore/terms/'),
              'oa' : Namespace('http://www.w3.org/ns/oa#'),
              'cnt' : Namespace('http://www.w3.org/2011/content#'),
Пример #7
0
@author: Paul

takes a uri query string and displays everything at the corresponding url as a table
this is intentionally a very simple method and will be elaborated on

TODO 
templating rather than string concatenation
Error handling
'''
from django.http import HttpResponse
from django.template import Template, Context

import rdflib
import rdfextras
rdfextras.registerplugins() # so we can Graph.parse()

def uriViewer(request):
    if request.GET.get('uri'):
        uri = request.GET['uri']
        g=rdflib.Graph()
        g.parse(uri)
        results = g.query("""
                SELECT ?p ?o
                WHERE {
                <%s> ?p ?o.
                }
                ORDER BY (?p)
                """ % uri)
        labels = g.query("""
                SELECT ?label
Пример #8
0
import rdfextras
import rdflib
from flask import Flask, send_from_directory, request, jsonify
from flask_cors import CORS

rdfextras.registerplugins()

app = Flask(__name__)
CORS(app)
# Basic configuration of the app
fileFinki = "/home/wbsfinki/mysite/finki.ttl"

ns = {
    "foaf": rdflib.Namespace("http://xmlns.com/foaf/0.1/"),
    "wbsfinki": rdflib.Namespace("http://wbsfinki.pythonanywhere.com/data#"),
    "aiiso": rdflib.Namespace("http://purl.org/vocab/aiiso/schema#"),
    "aiiso-roles":
    rdflib.Namespace("http://purl.org/vocab/aiiso-roles/schema#"),
    "rdfs": rdflib.RDFS,
    "rdf": rdflib.RDF,
    "dbo": rdflib.Namespace("http://dbpedia.org/ontology/"),
    "schema": rdflib.Namespace("http://schema.org/")
}

# Home Route
#@app.route("/")
#def _main():
#    return jsonify({"success": True})


@app.route("/create_ontology")
__author__ = 'PwC EU Services'

from json_mapping_estonia import json_to_rdf
import time

from configparser import ConfigParser

import requests
from SPARQLWrapper import SPARQLWrapper, POST, JSON
from rdflib import Graph
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore
from termcolor import colored
import sys
import rdfextras

rdfextras.registerplugins() # so we can Graph.query()

headers = {'content-type': 'application/json'}  # HTTP header content type
# Configurations
config = ConfigParser()
config.read('config.ini')

URI = sys.argv[1]
classType = sys.argv[2]

endpoint_uri = config['Mandatory']['endpointURI']
graph_uri = config['Mandatory']['graphURI']

# Set up endpoint and access to triple store
sparql = SPARQLWrapper(endpoint_uri)
sparql.setReturnFormat(JSON)
Пример #10
0
    async def final_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
        ten_le_hoi = step_context.result
        # print(ten_le_hoi)
        import rdfextras
        rdfextras.registerplugins()
        filename = "../../OntologyFile/fesivalVietNam.owl"
        import rdflib
        g = rdflib.Graph()
        result = g.parse(filename, format='xml')
        
        count_ten_le_hoi=0
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?name
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",step_context.result)
        for row in g.query(query):
            count_ten_le_hoi+=1

        #tìm lễ hội thông qua tên khác
        test=0
        if count_ten_le_hoi==0:
            pass
            count_ten_khac=0
            query = """
                PREFIX owl: <http://www.w3.org/2002/07/owl#>    
                PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
                PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
                PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
                PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

                SELECT DISTINCT ?name
                WHERE 
                { 
                ?x :tenLeHoi ?name.
                ?x :tenKhac ?a.
                FILTER( regex(?a,"fes","i") ) 
                }

                """
            query=query.replace("fes",step_context.result)
            cac_le_hoi=[]
            for row in g.query(query):
                a="%s" % row
                cac_le_hoi.append(a)
                count_ten_khac+=1
            
            if count_ten_khac==0:
                get_text = "Không tìm thấy lễ hội này"
                get_message = MessageFactory.text(
                get_text, get_text, InputHints.ignoring_input
                    )
                await step_context.context.send_activity(get_message)
                return await step_context.next(None)

            if count_ten_khac==1:
                test=1
                for x in cac_le_hoi:
                    get_text=step_context.result
                    ten_le_hoi=x
                get_text+=" là tên khác của " + ten_le_hoi
                get_message = MessageFactory.text(
                get_text, get_text, InputHints.ignoring_input
                    )
                await step_context.context.send_activity(get_message)
            
            if count_ten_khac>1:
                get_text = ten_le_hoi+" là tên khác của: "
                for x in cac_le_hoi:
                    get_text += x
                    get_text += ", "
                get_text+="... Bạn hãy nhập tên 1 trong các lễ hội kể trên để tìm kiếm thêm thông tin."
                get_message = MessageFactory.text(
                get_text, get_text, InputHints.ignoring_input
                    )
                await step_context.context.send_activity(get_message)
                return await step_context.next(None)
        
        #các thông tin về lễ hội
        #query loc
        data=[]
        count = 0
        get_text = ""
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?data
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :toChucTai ?loc.
            ?loc :tenDiaDiem ?data.
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",ten_le_hoi)
        get_text += "Tổ chức tại "
        for row in g.query(query):
            a="%s" % row
            for x in data:
                if a==x:
                    break
            data.append(a)
        for x in data:
            get_text += x
            get_text += " "
            count +=1
        get_text += "."
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0

        #query time
        data=[]
        count = 0
        get_text = ""
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?data
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :thoiGianToChuc ?data.
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",ten_le_hoi)
        get_text += "Tổ chức vào "
        for row in g.query(query):
            a="%s" % row
            for x in data:
                if a==x:
                    break
            data.append(a)
        for x in data:
            get_text += x.lower()
            get_text += " "
            count +=1
        get_text += "."
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0

        #query ten khac
        data=[]
        count = 0
        get_text = ""
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?data
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :tenKhac ?data.
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",ten_le_hoi)
        if test==0:
            get_text += "Còn có tên gọi khác là: "
            for row in g.query(query):
                a="%s" % row
                for x in data:
                    if a==x:
                        break
                data.append(a)
            for x in data:
                get_text += x
                get_text += ", "
                count +=1
            get_text += "..."
            if count != 0:
                get_message = MessageFactory.text(
                get_text, get_text, InputHints.ignoring_input
                    )
                await step_context.context.send_activity(get_message)
            data.clear()
            get_text = ""
            count=0
            
        #query lich su
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?data
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :lichSu ?data.
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",ten_le_hoi)
        get_text += "Lịch sử: "
        for row in g.query(query):
            a="%s" % row
            data.append(a)
        for x in data:
            get_text += x.lower()
            get_text += " "
            count +=1
        get_text += "."
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0
        
         #query ton giao
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?data
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :cuaTonGiao ?data.
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",ten_le_hoi)
        for row in g.query(query):
            get_text +="%s là lễ hội của %s " % row
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0

        #query act
        query = """
         PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?data
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :coHoatDong ?a.
            ?a :tenHoatDong ?data.
            FILTER( regex(?name,"fes","i") ) 
            }
        """
        query=query.replace("fes",ten_le_hoi)
        get_text += "Trong lễ hội có các hoạt động như: "
        for row in g.query(query):
            a="%s" % row
            data.append(a)
        for x in data:
            get_text += x.lower() 
            get_text += ", "
            count +=1
        get_text += "..."
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0

        #query muc dich
        query = """
         PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?data
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :nhamHuongDen ?a.
            ?a :noiDungMucDich ?data.
            FILTER( regex(?name,"fes","i") ) 
            }
        """
        query=query.replace("fes",ten_le_hoi)
        get_text += " Mục đích của lễ hội là: "
        for row in g.query(query):
            a="%s" % row
            data.append(a)
        for x in data:
            get_text += x.lower() 
            get_text += ", "
            count +=1
        get_text += "..."
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0

        #query danh hieu
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?d3 ?d1 
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :duocCongNhan ?d.
            ?d :tenDanhHieu ?d1.
            ?d :congNhanBoi ?d2.
            ?d2 :tenToChuc ?d3
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",ten_le_hoi)
        get_text += "Lễ hội được "
        for row in g.query(query):
            get_text +="%s công nhận %s" % row
            get_text += "; "
            count +=1
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0

        #query link
        query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?link
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :linkChiTiet ?link
            FILTER( regex(?name,"fes","i") ) 
            }

            """
        query=query.replace("fes",ten_le_hoi)
        get_text += "Bạn có thể tham khảo chi tiết thông tin về " + step_context.result + " trong link bài viết sau: "
        for row in g.query(query):
            get_text +="%s" % row
            count +=1
        if count != 0:
            get_message = MessageFactory.text(
            get_text, get_text, InputHints.ignoring_input
                )
            await step_context.context.send_activity(get_message)
        data.clear()
        get_text = ""
        count=0
        
        return await step_context.next(None)
__author__ = 'PwC EU Services'

from json_mapping_estonia import json_to_rdf
import time

from configparser import ConfigParser

import requests
from SPARQLWrapper import SPARQLWrapper, POST, JSON
from rdflib import Graph
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore
from termcolor import colored
import sys
import rdfextras

rdfextras.registerplugins()  # so we can Graph.query()

headers = {'content-type': 'application/json'}  # HTTP header content type
# Configurations
config = ConfigParser()
config.read('config.ini')

uri = sys.argv[1]

endpoint_uri = config['Mandatory']['endpointURI']
graph_uri = config['Mandatory']['graphURI']

# Set up endpoint and access to triple store
sparql = SPARQLWrapper(endpoint_uri)
sparql.setReturnFormat(JSON)
sparql.setMethod(POST)
Пример #12
0
    async def confirm_step(
            self, step_context: WaterfallStepContext) -> DialogTurnResult:
        """
        Confirm the information the user has provided.
        :param step_context:
        :return DialogTurnResult:
        """
        count = 0
        goiylehoi_details = step_context.options
        goiylehoi_details.diaDiem = step_context.result
        import rdfextras
        rdfextras.registerplugins()
        # filename = "fesivalVietNam.owl"
        filename = "../../OntologyFile/fesivalVietNam.owl"
        import rdflib
        g = rdflib.Graph()

        result = g.parse(filename, format='xml')
        # print(result)
        query = """
        PREFIX owl: <http://www.w3.org/2002/07/owl#>    
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
        PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
        PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
        PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

        SELECT DISTINCT ?name
        WHERE 
        { 
        ?x :tenLeHoi ?name.
        ?x :coHoatDong ?act.
        ?x :toChucTai ?loc.
        ?act rdfs:label ?l.
        ?act :tenHoatDong ?nact.
        ?loc :tenDiaDiem ?nloc.
        FILTER( regex(?nloc,"diaDiem","i") ) 
        FILTER( regex(?l,"hoatDong","i") ) 
        }

        """
        query = query.replace("diaDiem", goiylehoi_details.diaDiem)
        query = query.replace("hoatDong", goiylehoi_details.hoatDong)
        for row in g.query(query):
            fes = "%s" % row
            count += 1
            data = []
            query1 = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?nact
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :coHoatDong ?act.
            ?act rdfs:label ?l.
            ?act :tenHoatDong ?nact.
            FILTER( regex(?name,"fes","i") ) 
            FILTER( regex(?l,"hoatDong","i") ) 
            }

            """
            if count == 1:
                get_text = "Bạn có thể tham gia du lịch ở các lễ hội như:"
                get_message = MessageFactory.text(get_text, get_text,
                                                  InputHints.ignoring_input)
                await step_context.context.send_activity(get_message)
            query1 = query1.replace("fes", fes)
            query1 = query1.replace("hoatDong", goiylehoi_details.hoatDong)
            get_text = fes + " với các hoạt động "
            for row in g.query(query1):
                a = "%s" % row
                for x in data:
                    if a == x:
                        break
                data.append(a)
            for x in data:
                get_text += x
                get_text += ", "
            get_text += "..."
            get_message = MessageFactory.text(get_text, get_text,
                                              InputHints.ignoring_input)
            await step_context.context.send_activity(get_message)
            data.clear()
            get_text = ""

        if count == 0:
            get_text = "Hiện tại chưa tìm được lễ hội bạn mong muốn ở " + goiylehoi_details.diaDiem + ". Bạn có thể tham khảo 1 vài lễ hội ở các địa phương khác như:"
            get_message = MessageFactory.text(get_text, get_text,
                                              InputHints.ignoring_input)
            await step_context.context.send_activity(get_message)
            query = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?name
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :coHoatDong ?act.
            ?act rdfs:label ?l.
            ?act :tenHoatDong ?nact.
            FILTER( regex(?l,"hoatDong","i") ) 
            }

            """
            query = query.replace("hoatDong", goiylehoi_details.hoatDong)
            for row in g.query(query):
                fes = "%s" % row
                count += 1
                if count == 6:
                    break
                data = []
                query1 = """
                PREFIX owl: <http://www.w3.org/2002/07/owl#>    
                PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
                PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
                PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
                PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

                SELECT DISTINCT ?nloc
                WHERE 
                { 
                ?x :tenLeHoi ?name.
                ?x :coHoatDong ?act.
                ?x :toChucTai ?loc.
                ?loc :tenDiaDiem ?nloc.
                FILTER( regex(?name,"fes","i") )  
                }

                """
                query1 = query1.replace("fes", fes)
                get_text = fes + " tổ chức tại "
                for row in g.query(query1):
                    a = "%s" % row
                    data.append(a)
                for x in data:
                    get_text += x
                    get_text += " "
                get_message = MessageFactory.text(get_text, get_text,
                                                  InputHints.ignoring_input)
                await step_context.context.send_activity(get_message)
                data.clear()

        return await step_context.next(None)
Пример #13
0
    async def destination_step(
            self, step_context: WaterfallStepContext) -> DialogTurnResult:

        dantoc_details = step_context.options
        if not dantoc_details.danToc:
            return await step_context.next(None)
        import rdfextras
        rdfextras.registerplugins()
        filename = "../../OntologyFile/fesivalVietNam.owl"
        import rdflib
        g = rdflib.Graph()
        result = g.parse(filename, format='xml')

        query = """
        PREFIX owl: <http://www.w3.org/2002/07/owl#>    
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
        PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
        PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
        PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

        SELECT DISTINCT ?name
        WHERE 
        { 
        ?x :tenLeHoi ?name.
        ?x :cuaDanToc ?eth.
        ?eth :tenDanToc ?neth.
        FILTER( regex(?neth,"danToc","i")) 
        }

        """
        query = query.replace("danToc", dantoc_details.danToc)
        count = 0
        for row in g.query(query):
            fes = "%s" % row
            loc = []
            query1 = """
            PREFIX owl: <http://www.w3.org/2002/07/owl#>    
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>   
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>    
            PREFIX xml: <http://www.w3.org/XML/1998/namespace>  
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
            PREFIX :<http://www.semanticweb.org/admin/ontologies/2020/2/untitled-ontology-5#> 

            SELECT DISTINCT ?nloc
            WHERE 
            { 
            ?x :tenLeHoi ?name.
            ?x :toChucTai ?loc.
            ?loc :tenDiaDiem ?nloc.
            FILTER( regex(?name,"fes","i") ) 
            }

            """
            query1 = query1.replace("fes", fes)
            get_text = fes + " tổ chức tại "
            for row in g.query(query1):
                a = "%s" % row
                for x in loc:
                    if a == x:
                        break
                loc.append(a)
            for x in loc:
                get_text += x
                get_text += " "
            get_message = MessageFactory.text(get_text, get_text,
                                              InputHints.ignoring_input)
            await step_context.context.send_activity(get_message)
            loc.clear()
            count += 1
        if count == 0:
            get_text = "Chưa tìm thấy lễ hội nào của người dân tộc " + dantoc_details.danToc
            get_message = MessageFactory.text(get_text, get_text,
                                              InputHints.ignoring_input)
            await step_context.context.send_activity(get_message)
            return await step_context.next(None)
            # return await step_context.next(next(dantoc_details.danToc))
        return await step_context.next(None)
Пример #14
0
	     writes files test/obi.json and test/obi.tsv into test/ subfolder.


	FUTURE: Get ontology version, and add to output core filename ???
	
	**************************************************************************
""" 

import json
import sys
import os
import optparse
import python.ontohelper as oh

import rdflib
import rdfextras; rdfextras.registerplugins() # so we can Graph.query()

# Do this, otherwise a warning appears on stdout: No handlers could be 
#found for logger "rdflib.term"
import logging; logging.basicConfig(level=logging.ERROR) 

try: #Python 2.7
	from collections import OrderedDict
except ImportError: # Python 2.6
	from ordereddict import OrderedDict

def stop_err(msg, exit_code = 1):
	sys.stderr.write("%s\n" % msg)
	sys.exit(exit_code)

class MyParser(optparse.OptionParser):
Пример #15
0
 def __init__(self, filename):
     self.filename = filename
     rdfextras.registerplugins()
     self.g = rdflib.Graph()
     self.g.parse(filename)
def SSW_init():
        
    print "\n------------------------------------------------------------------------------------"
    print "| WELCOME TO TURKUAZURCHESE, A TOOL TO FIND FLAMES AMONG CONVERSATIONS IN TWITTER! |"
    print "------------------------------------------------------------------------------------"
    print "                     by Federico Montori and Mehmet Durna"
    print "                     Social Network Analysis\n\n"
    
    #     ## DEPRECATED
    #     # If the program is called with the -e option it includes the extraction from twitterS
    #     if '-e' in sys.argv:
    #         sys.stdout.write("Extracting users from file...")
    #         extract_from_file()
    #         sys.stdout.write("done!\n")
    #         
    #         sys.stdout.write("Extracting flamers from twitter... \n")    
    #         append_flamer(raw_flamers, -1)
    #         sys.stdout.write("\nExtracting non-flamers from twitter... \n")
    #         append_flamer(raw_noflamers, 1)
    #         sys.stdout.write("\n... done!\n")
    #         
    #         with open("almost_final", 'w') as fn:
    #             fn.write(str(res_flamers))
    
    
    # TEST
    #     ciao = getUserAll('1352597610')
    #     print ciao
    #     sys.exit()
    
    # If the program is called with the -e option it includes the extraction from twitterS
    if '-e' in sys.argv:    
    #     with open("almost_final", 'r') as f:
    #         rawtxt = eval(f.read())
        with open('raw_users','r') as f:
            userdict = eval(f.read())
            
    # IT WORKS!!!!!
#     user = '******'
#     user2 = 'climagic'
#     print api.show_friendship(source_screen_name=user, target_screen_name=user2)[0].following
#     exit()
    
    #with open('SNA/social_graph.rdf', 'w') as f:
        with open('SNA/social_graph_fn.rdf', 'w') as f:
        
            f.write("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" xmlns:owl=\"http://www.w3.org/2002/07/owl#\" xmlns:xs=\"http://www.w3.org/2000/10/XMLSchema#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns=\"http://www.w3.org/2000/10/XMLSchema#\" xml:base=\"http://www.fedemontori.eu/ns#\" xmlns:tto=\"http://www.fedemontori.eu/ns#\" xmlns:sioc=\"http://rdfs.org/sioc/ns#\" xmlns:foaf=\"http://xmlns.com/foaf/0.1/\"> <owl:Ontology rdf:about=\"http://www.fedemontori.eu\"> <dc:title xml:lang=\"en\"> TurkuazTurkese core ontology </dc:title> <owl:versionInfo> Revision: 1.2 </owl:versionInfo> <dc:description xml:lang=\"en\"> TurkuazTurcheseOnto is an extension of sioc used to represent concepts like flaming and non-flaming conversation (so weighted relationships) </dc:description> </owl:Ontology> <!-- top concepts --> <owl:Class rdf:ID=\"Conversation\"> <rdfs:subClassOf rdf:resource=\"sioc:Forum\"/> <label xml:lang=\"en\"> TTO conversation </label> <comment xml:lang=\"en\"> A class that represents a conversation among more people. </comment> </owl:Class> <owl:ObjectProperty rdf:ID=\"hasConversation\"> <range rdf:resource=\"#Conversation\"/> <label xml:lang=\"en\"> has Conversation </label> <comment xml:lang=\"en\"> Links personally an user to a conversation, let's say from his point of view. </comment> </owl:ObjectProperty> <owl:ObjectProperty rdf:ID=\"hasCorrespondant\"> <range rdf:resource=\"#UserAccount\"/> <label xml:lang=\"en\"> has Correspondant user </label> <comment xml:lang=\"en\"> link a conversation with its correspondants </comment> </owl:ObjectProperty>")
              
            for idx, user in enumerate(userdict.keys()):
                # complete_user = getUserAll(user)
                print "------ " + str(idx) + " " + user
                sioc_user = "******"https://www.twitter.com/" + user + "\" rdfs:label=\"Cloud\">"
                for tple in userdict[user]:
                    uid = str(uuid.uuid4())
                    sioc_user += "<foaf:knows rdf:resource=\"https://www.twitter.com/" + tple[2] + "\"/>"
                    sioc_user += "<tto:hasRelationship>"
                    sioc_user += "<tto:Relationship rdf:about=\"http://www.fedemontori.eu/#" + uid + "\"> <tto:flame>" + str(tple[1]) + "</tto:flame> <tto:value rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">" + str(tple[0]) + "</tto:value>"
                    sioc_user += "<tto:hasCorrespondant rdf:resource=\"https://www.twitter.com/" + tple[2] + "\" />"
                    sioc_user += "</tto:Relationship></tto:hasRelationship>"
#                     
                    if retrieve_friendship(user, tple[2]) == True:
                        print "        found one!"
                        sioc_user += "<sioc:follows rdf:resource=\"https://www.twitter.com/" + tple[2] + "\"/>"
                        
                sioc_user += "</sioc:UserAccount>"
                
            #         for tple in rawtxt:
            #             for user in tple.keys():
            #                 weight = tple[user]
            #                 if weight > 0: fl = "noflame"
            #                 else: fl = "flame"
            #                 uid = str(uuid.uuid4())
            #                 sioc_user = "******"https://www.twitter.com/" + user[0] + "\" rdfs:label=\"Cloud\">"
            #                 sioc_user += "<tto:hasRelationship rdf:resource=\"http://www.fedemontori.eu/#" + uid + "\"/>"
            #                 for user2 in tple.keys():
            #                     if not user2 == user:
            #                         sioc_user += "<foaf:knows rdf:resource=\"https://www.twitter.com/" + user2[0] + "\"/>"
            #                 sioc_user += "</sioc:UserAccount> <tto:Relationship rdf:about=\"http://www.fedemontori.eu/#" + uid + "\" flame=\"" + fl + "\"> <tto:value rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">" + str(abs(weight)) + "</tto:value>"
            #                 for user2 in tple.keys():
            #                     if not user2 == user:
            #                         sioc_user += "<tto:hasCorrespondant rdf:resource=\"https://www.twitter.com/" + user2[0] + "\" />"
            #                 sioc_user += "</tto:Relationship>"
            #                 
                f.write(sioc_user)
                                         
            f.write("</rdf:RDF>")

    # Activate the rdf plugin on the variable graph
    rdfgraph = Graph()
    rdfextras.registerplugins() # so we can Graph.query()
    rdfgraph.parse('SNA/social_graph_fn.rdf')
    
    with open('SNA/social_graph_fn.rdf', 'w') as sgr: 
        sgr.write(rdfgraph.serialize(format='pretty-xml'))
     
    alltuples = rdfgraph.query("SELECT ?s ?w ?o ?f WHERE { ?s tto:hasRelationship ?r . ?r tto:value ?w . ?r tto:flame ?f . ?r tto:hasCorrespondant ?o }")
    # result = rdfgraph.query("SELECT ?o WHERE { <https://www.twitter.com/ArkanKurd> <http://ns.inria.fr/semsna/2009/06/21/value> ?o } ")
    # result = rdfgraph.query("SELECT ?y WHERE { ?x $path ?y }")# . FILTER match($path, foaf:knows) }")# FILTER (pathLength($path) >= 1 && pathLength($path) <= 2)") 
     
    for res in alltuples:
        print res
    print len(alltuples)