示例#1
0
def save_note():
	# convert string to list of json objects
	json_data = json.loads(request.args.get('data'))

	# iterate through list, converting and adding notes to turtle array
	turtle_data = []
	for i, json_obj in enumerate(json_data):
		turtle_data.append(to_turtle(json_obj))
	
	# add each turtle note to the string that will be sent to Fuseki
	# use array because python passes strings by value, making additions inefficient
	turtle_file = ''
	for turtle_obj in turtle_data:
		turtle_file += "\n"
		turtle_file += turtle_obj
	
	# add prefixes then send all notes to Fuseki
	insert_me = set_prefix()
	insert_me += "\n INSERT { %s } WHERE {}" %turtle_file
	sparql = SPARQLWrapper(triplestore_url + "/update")
	
	sparql.setQuery(insert_me) 
	sparql.method = 'POST'
	sparql.query()

	return jsonify(result="success")
示例#2
0
def save_note():
    # convert string to list of json objects
    json_data = json.loads(request.args.get('data'))

    # iterate through list, converting and adding notes to turtle array
    turtle_data = []
    for i, json_obj in enumerate(json_data):
        turtle_data.append(to_turtle(json_obj))

    # add each turtle note to the string that will be sent to Fuseki
    # use array because python passes strings by value, making additions inefficient
    turtle_file = ''
    for turtle_obj in turtle_data:
        turtle_file += "\n"
        turtle_file += turtle_obj

    # add prefixes then send all notes to Fuseki
    insert_me = set_prefix()
    insert_me += "\n INSERT { %s } WHERE {}" % turtle_file
    sparql = SPARQLWrapper(triplestore_url + "/update")

    sparql.setQuery(insert_me)
    sparql.method = 'POST'
    sparql.query()

    return jsonify(result="success")
示例#3
0
def create_sparql_query(doc_uri):
	query = set_prefix()
	# query looks in this order:
	# 1. entire doc note info with [] as subject
	# 2. fragment note info with [] as subject
	# 3. fragment note target info
	# 4. publication year body
	# 5. cites body
	# 6. value for entire body notes
	# 7. value for fragment notes
	# 8/9. annotator email
	query += """
	select ?s ?p ?o
	where {
		{	?s oa:hasTarget ao:""" + doc_uri + """ .
			?s ?p ?o .
		}
		union
		{ 	?s oa:hasTarget ?target .
			?target oa:hasSource ao:""" + doc_uri + """ .
			?s ?p ?o .
		}
		union
		{	?s oa:hasTarget ?target .
			?target oa:hasSource ao:""" + doc_uri + """ .
			?target oa:hasSelector ?selector .
			?selector ?p ?o .
		}
		union
		{	?s oa:hasTarget ao:""" + doc_uri + """ .
			?s oa:hasBody ?body .
			?body rdf:predicate ?p .
			?body rdf:object ?o .
		}
		union
		{	?s oa:hasTarget ?target .
			?target oa:hasSource ao:""" + doc_uri + """ .
			?s oa:hasBody ?body .
			?body rdf:predicate ?p .
			?body rdf:object ?o .
		}
		union
		{	?s oa:hasTarget ao:""" + doc_uri + """ .
	  		?s oa:hasBody ?body .
          		?body a cnt:ContentAsText .
	  		?body ?p ?o .
		}
		union 
		{	?s oa:hasTarget ?target .
          		?target oa:hasSource ao:""" + doc_uri + """ .
	  		?s oa:hasBody ?body .
          		?body a cnt:ContentAsText .
          		?body ?p ?o .
		}
		union
		{	?s oa:hasTarget ao:""" + doc_uri + """ .
			?s oa:annotatedBy ?person .
			?person ?p ?o .
		}
		union
		{ 	?s oa:hasTarget ?target .
			?target oa:hasSource ao:""" + doc_uri + """ .
			?s oa:annotatedBy ?person .
			?person ?p ?o .
		}
	} order by ?s"""
	return query;