Exemplo n.º 1
0
    def generate(cls, utensils):
        graph = ConjunctiveGraph()
        load_rdf_file(STORE['actions'], graph)

        for utensil in utensils:
            for action in utensil.actions:
                map(rdfSubject.db.add, graph.triples((action.resUri, None, None)))
Exemplo n.º 2
0
def sparql_endpoint():
    """ Le endpoint sparql"""
    query = unquote(request.args.get('query'))

    g = Graph()

    for filename in STORE.itervalues():
        load_rdf_file(filename, g)

    return g.query(query)
Exemplo n.º 3
0
def add_utensil():
    """ Ajouter un ustensile """
    store_file = STORE['utensils']
    label = request.json['label']
    actions = [create_uri(uri) for uri in request.json['actions']]

    uri = create_uri(BASE_URI_UTENSIL + sanitize(label))

    load_rdf_file(store_file)
    Utensil(resUri=uri, label=label, actions=actions)
    save_rdf_file(store_file)

    return jsonify({'uri': uri})
Exemplo n.º 4
0
def add_action():
    """ Ajouter une action """
    store_file = STORE['actions']
    label = request.json['label']

    uri = create_uri(BASE_URI_ACTION + sanitize(label))

    load_rdf_file(store_file)
    Action(resUri=uri, label=label)
    save_rdf_file(store_file)

    # On retourne une chaine vide pour renvoyer un code HTTP 200
    return jsonify({'uri': uri})
Exemplo n.º 5
0
    def generate(cls, n):
        graph = ConjunctiveGraph()
        load_rdf_file(STORE['utensils'], graph)

        all_uris = set(graph.subjects())
        n = min(n, len(all_uris))
        selected_uris = sample(all_uris, n)

        # On récupère les ustensiles voulus dans le graphe
        selected_triples = chain(*map(graph.triples, ((uri, None, None) for uri in selected_uris)))
        map(rdfSubject.db.add, selected_triples)

        utensils = [Utensil(uri) for uri in selected_uris]

        # On récupère les actions de ces ustensiles
        ActionGenerator.generate(utensils)

        return utensils
Exemplo n.º 6
0
def add_utensil_actions():
    """ Ajouter des actions à un ustensile """
    NS1 = Namespace('http://www.random-food.com/ontology#')
    store_file = STORE['utensils']
    dataj = json.loads(request.data)
    
    g = Graph()
    load_rdf_file(store_file, g)
    for s, p ,o in g.triples((None, RDF.type, NS1.Utensil)):
        if s.__str__() == dataj["utensil"]:
            print s
            for a, b, c in g.triples((s, NS1.Action,None)):
                print "remove"
                g.remove((a, b, c))

            for action in dataj["actions"]:
                g.add((s, NS1.Action, URIRef(action['uri'])))
    save_rdf_file(STORE['utensils'], g) 

    return jsonify({'uri': "test"})
Exemplo n.º 7
0
def get_actions():
    """ Liste toutes les actions """
    load_rdf_file(STORE['actions'])
    return get_rdf_graph()
Exemplo n.º 8
0
def get_utensils():
    """ Liste tous les ustensiles """
    load_rdf_file(STORE['utensils'])
    return get_rdf_graph()