コード例 #1
0
def load_single(orcid_id, person_uri, person_id, person_class, data_path, endpoint, username, password,
                namespace=None, skip_person=False, confirmed_orcid_id=False):
    with Store(data_path) as store:
        #Crosswalk
        (graph, profile, person_uri) = default_execute(orcid_id, namespace=namespace, person_uri=person_uri,
                                                       person_id=person_id, skip_person=skip_person,
                                                       person_class=person_class, confirmed_orcid_id=confirmed_orcid_id)

        graph_filepath = os.path.join(data_path, "%s.ttl" % orcid_id.lower())
        previous_graph = Graph(namespace_manager=ns_manager)
        #Load last graph
        if os.path.exists(graph_filepath):
            log.debug("Loading previous graph %s", graph_filepath)
            previous_graph.parse(graph_filepath, format="turtle")

        #Diff against last graph
        (both_graph, delete_graph, add_graph) = graph_diff(previous_graph, graph)

        #SPARQL Update
        log.info("Adding %s, deleting %s triples for %s", len(add_graph), len(delete_graph), orcid_id)
        sparql_delete(delete_graph, endpoint, username, password)
        sparql_insert(add_graph, endpoint, username, password)

        #Save new last graph
        log.debug("Saving new graph %s", graph_filepath)
        with codecs.open(graph_filepath, "w") as out:
            graph.serialize(format="turtle", destination=out)

        #Touch
        store.touch(orcid_id)

        return graph, add_graph, delete_graph
コード例 #2
0
def load_single(orcid_id, person_uri, person_id, person_class, data_path, endpoint, username, password,
                namespace=None, skip_person=False, confirmed_orcid_id=False):
    with Store(data_path) as store:
        #Crosswalk
        (graph, profile, person_uri) = default_execute(orcid_id, namespace=namespace, person_uri=person_uri,
                                                       person_id=person_id, skip_person=skip_person,
                                                       person_class=person_class, confirmed_orcid_id=confirmed_orcid_id)

        graph_filepath = os.path.join(data_path, "%s.ttl" % orcid_id.lower())
        previous_graph = Graph(namespace_manager=ns_manager)
        #Load last graph
        if os.path.exists(graph_filepath):
            log.debug("Loading previous graph %s", graph_filepath)
            previous_graph.parse(graph_filepath, format="turtle")

        #Diff against last graph
        (both_graph, delete_graph, add_graph) = graph_diff(previous_graph, graph)

        #SPARQL Update
        log.info("Adding %s, deleting %s triples for %s", len(add_graph), len(delete_graph), orcid_id)
        sparql_delete(delete_graph, endpoint, username, password)
        sparql_insert(add_graph, endpoint, username, password)

        #Save new last graph
        log.debug("Saving new graph %s", graph_filepath)
        with codecs.open(graph_filepath, "w") as out:
            graph.serialize(format="turtle", destination=out)

        #Touch
        store.touch(orcid_id)

        return graph, add_graph, delete_graph
コード例 #3
0
def crosswalk():
    session["format"] = request.form.get("format")
    endpoint = request.form.get("endpoint")
    session["endpoint"] = endpoint
    session["username"] = request.form.get("username")
    session["password"] = request.form.get("password")
    person_class = request.form.get("person_class")
    session["person_class"] = person_class
    session["skip_person"] = True if "skip_person" in request.form else False
    session["confirmed"] = True if "confirmed" in request.form else False
    session["output"] = request.form.get("output")
    session["output_html"] = True if "output_html" in request.form else False
    session[
        "output_profile"] = True if "output_profile" in request.form else False

    #Excute with default strategies
    (g, p, per_uri) = default_execute(
        request.form["orcid_id"],
        namespace=request.form["namespace"],
        person_uri=request.form["person_uri"],
        person_id=request.form["person_id"],
        skip_person=True if "skip_person" in request.form else False,
        person_class=person_class if person_class != "Person" else None,
        confirmed_orcid_id=True if "confirmed" in request.form else False)

    if "output" in request.form and request.form["output"] == "vivo":
        utility.sparql_insert(g, endpoint, request.form["username"],
                              request.form["password"])
        msg = "Loaded to VIVO"
        if endpoint.endswith("api/sparqlUpdate"):
            vivo_profile_url = "%s/individual?%s" % (
                endpoint[:-17], urllib.urlencode({"uri": per_uri}))
            msg += ". Try <a href=\"%s\">%s</a>." % (vivo_profile_url,
                                                     vivo_profile_url)
        flash(Markup(msg))
        return crosswalk_form()
    else:
        #Serialize
        rdf = g.serialize(format=request.form['format'], encoding="utf-8")
        if "output_html" in request.form or "output_profile" in request.form:
            return crosswalk_form(
                rdf=rdf if "output_html" in request.form else None,
                orcid_profile=p if "output_profile" in request.form else None)
        else:
            return Response(rdf,
                            content_type=content_types[request.form['format']])
コード例 #4
0
def crosswalk():
    session["format"] = request.form.get("format")
    endpoint = request.form.get("endpoint")
    session["endpoint"] = endpoint
    session["username"] = request.form.get("username")
    session["password"] = request.form.get("password")
    person_class = request.form.get("person_class")
    session["person_class"] = person_class
    session["skip_person"] = True if "skip_person" in request.form else False
    session["confirmed"] = True if "confirmed" in request.form else False
    session["output"] = request.form.get("output")
    session["output_html"] = True if "output_html" in request.form else False
    session["output_profile"] = True if "output_profile" in request.form else False

    #Excute with default strategies
    (g, p, per_uri) = default_execute(request.form["orcid_id"],
                                      namespace=request.form["namespace"],
                                      person_uri=request.form["person_uri"],
                                      person_id=request.form["person_id"],
                                      skip_person=True if "skip_person" in request.form else False,
                                      person_class=person_class if person_class != "Person" else None,
                                      confirmed_orcid_id=True if "confirmed" in request.form else False)

    if "output" in request.form and request.form["output"] == "vivo":
        utility.sparql_insert(g, endpoint, request.form["username"], request.form["password"])
        msg = "Loaded to VIVO"
        if endpoint.endswith("api/sparqlUpdate"):
            vivo_profile_url = "%s/individual?%s" % (endpoint[:-17], urllib.urlencode({"uri": per_uri}))
            msg += ". Try <a href=\"%s\">%s</a>." % (vivo_profile_url, vivo_profile_url)
        flash(Markup(msg))
        return crosswalk_form()
    else:
        #Serialize
        rdf = g.serialize(format=request.form['format'], encoding="utf-8")
        if "output_html" in request.form or "output_profile" in request.form:
            return crosswalk_form(rdf=rdf if "output_html" in request.form else None,
                                  orcid_profile=p if "output_profile" in request.form else None)
        else:
            return Response(rdf, content_type=content_types[request.form['format']])
コード例 #5
0
    parser.add_argument("--person-class", dest="person_class",
                        choices=["FacultyMember", "FacultyMemberEmeritus", "Librarian", "LibrarianEmeritus",
                                 "NonAcademic", "NonFacultyAcademic", "ProfessorEmeritus", "Student"],
                        help="Class (in VIVO Core ontology) for a person. Default is a FOAF Person.")
    parser.add_argument("--skip-person", dest="skip_person", action="store_true",
                        help="Skip adding triples declaring the person and the person's name.")
    parser.add_argument("--confirmed", action="store_true", help="Mark the orcid id as confirmed.")

    # Parse
    args = parser.parse_args()

    # Excute with default strategies
    (g, p, per_uri) = default_execute(args.orcid_id, namespace=args.namespace, person_uri=args.person_uri,
                                      person_id=args.person_id, skip_person=args.skip_person,
                                      person_class=args.person_class, confirmed_orcid_id=args.confirmed)

    # Write to file
    if args.file:
        with codecs.open(args.file, "w") as out:
            g.serialize(format=args.format, destination=out)

    # Post to SPARQL Update
    if args.endpoint:
        if not args.username or not args.password:
            raise Exception("If an endpoint is specified, --username and --password must be provided.")
        sparql_insert(g, args.endpoint, args.username, args.password)

    # If not writing to file to posting to SPARQL Update then serialize to stdout
    if not args.file and not args.endpoint:
        print g.serialize(format=args.format)