コード例 #1
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
def remove_project_text(project_uri, text_uri):
    # Correctly format project uri and get project graph
    project_uri = uris.uri('semantic_store_projects', uri=project_uri)
    project_g = Graph(rdfstore(), identifier=project_uri)
    project_metadata_g = Graph(
        rdfstore(), identifier=uris.project_metadata_graph_identifier(p_uri))

    # Make text uri a URIRef (so Graph will understand)
    text_uri = URIRef(text_uri)

    with transaction.commit_on_success():
        for t in specific_resources_subgraph(project_g, text_uri, project_uri):
            project_g.remove(t)

        for t in project_g.triples((text_uri, None, None)):
            # Delete triple about text from project graph
            project_g.remove(t)
            project_metadata_g.remove(t)

        project_g.remove((URIRef(project_uri), NS.ore.aggregates, text_uri))

        for text in Text.objects.filter(identifier=text_uri,
                                        valid=True).only('valid'):
            text.valid = False
            text.save()
コード例 #2
0
def canvas_subgraph(graph, canvas_uri, project_uri):
    canvas_uri = URIRef(canvas_uri)

    canvas_graph = Graph()

    canvas_graph += canvas_and_images_graph(graph, canvas_uri)

    canvas_graph += resource_annotation_subgraph(graph, canvas_uri)

    canvas_graph += anno_lists_subgraph(graph, canvas_uri, project_uri)

    canvas_graph += specific_resources_subgraph(graph, canvas_uri, project_uri)

    return canvas_graph
コード例 #3
0
def update_project_text(g, p_uri, t_uri, user):
    # Correctly format project uri and get project graph
    project_uri = uris.uri('semantic_store_projects', uri=p_uri)
    project_g = Graph(rdfstore(), identifier=project_uri)
    project_metadata_g = Graph(rdfstore(), identifier=uris.project_metadata_graph_identifier(p_uri))
    text_uri = URIRef(t_uri)

    title = g.value(text_uri, NS.dc.title) or g.value(text_uri, NS.rdfs.label) or Literal("")
    content_value = g.value(text_uri, NS.cnt.chars)
    if content_value:
        content = sanitized_content(content_value)
    else:
        content = ''

    with transaction.commit_on_success():
        for t in Text.objects.filter(identifier=t_uri, valid=True):
            t.valid = False
            t.save()
            # While it looks like this would be better with a QuerySet update, we need to fire the save
            # events to keep the search index up to date. In all forseeable cases, this should only execute
            # for one Text object anyway.

        text = Text.objects.create(identifier=t_uri, title=title, content=content, last_user=user, project=p_uri)

        project_g.add((text_uri, NS.rdf.type, NS.dctypes.Text))
        project_g.set((text_uri, NS.dc.title, title))
        project_g.set((text_uri, NS.rdfs.label, title))

        text_url = URIRef(uris.url('semantic_store_project_texts', project_uri=p_uri, text_uri=text_uri))
        project_g.set((text_uri, NS.ore.isDescribedBy, text_url))

        if (URIRef(p_uri), NS.ore.aggregates, text_uri) in project_metadata_g:
            project_metadata_g.add((text_uri, NS.rdf.type, NS.dctypes.Text))
            project_metadata_g.set((text_uri, NS.dc.title, title))
            project_metadata_g.set((text_uri, NS.rdfs.label, title))

    specific_resource_triples = specific_resources_subgraph(g, text_uri, p_uri)
    for t in specific_resource_triples:
        project_g.add(t)

    for t in g.triples((None, NS.rdf.type, NS.oa.TextQuoteSelector)):
        project_g.set(t)
コード例 #4
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
def read_project_text(project_uri, text_uri):
    # Correctly format project uri and get project graph
    project_identifier = uris.uri('semantic_store_projects', uri=project_uri)
    project_g = Graph(rdfstore(), identifier=project_identifier)

    # Make text uri URIRef (so Graph will understand)
    text_uri = URIRef(text_uri)

    # Create an empty graph and bind namespaces
    text_g = Graph()
    bind_namespaces(text_g)

    text_g += resource_annotation_subgraph(project_g, text_uri)

    text_g += specific_resources_subgraph(project_g, text_uri, project_uri)

    overwrite_text_graph_from_model(text_uri, project_uri, text_g)

    # Return graph about text
    return text_g
コード例 #5
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
def read_project_text(project_uri, text_uri):
    # Correctly format project uri and get project graph
    project_identifier = uris.uri('semantic_store_projects', uri=project_uri)
    project_g = Graph(rdfstore(), identifier=project_identifier)

    # Make text uri URIRef (so Graph will understand)
    text_uri = URIRef(text_uri)

    # Create an empty graph and bind namespaces
    text_g = Graph()
    bind_namespaces(text_g)

    text_g += resource_annotation_subgraph(project_g, text_uri)

    text_g += specific_resources_subgraph(project_g, text_uri, project_uri)

    overwrite_text_graph_from_model(text_uri, project_uri, text_g)

    # Return graph about text
    return text_g
コード例 #6
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
def remove_project_text(project_uri, text_uri):
    # Correctly format project uri and get project graph
    project_uri = uris.uri('semantic_store_projects', uri=project_uri)
    project_g = Graph(rdfstore(), identifier=project_uri)
    project_metadata_g = Graph(rdfstore(), identifier=uris.project_metadata_graph_identifier(p_uri))

    # Make text uri a URIRef (so Graph will understand)
    text_uri = URIRef(text_uri)

    with transaction.commit_on_success():
        for t in specific_resources_subgraph(project_g, text_uri, project_uri):
            project_g.remove(t)

        for t in project_g.triples((text_uri, None, None)):
            # Delete triple about text from project graph
            project_g.remove(t)
            project_metadata_g.remove(t)

        project_g.remove((URIRef(project_uri), NS.ore.aggregates, text_uri))

        for text in Text.objects.filter(identifier=text_uri, valid=True).only('valid'):
            text.valid = False
            text.save()
コード例 #7
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
def update_project_text(g, p_uri, t_uri, user):
    logger.debug("************* Updating project")
    # Correctly format project uri and get project graph
    project_uri = uris.uri('semantic_store_projects', uri=p_uri)
    logger.debug("!!!!!!!!!!!!!! Here 1")
    project_g = Graph(rdfstore(), identifier=project_uri)
    logger.debug("!!!!!!!!!!!!!! Here 2")
    project_metadata_g = Graph(rdfstore(), identifier=uris.project_metadata_graph_identifier(p_uri))
    logger.debug("!!!!!!!!!!!!!! Here 3")
    text_uri = URIRef(t_uri)
    logger.debug("!!!!!!!!!!!!!! Here 4")

    title = g.value(text_uri, NS.dc.title) or g.value(text_uri, NS.rdfs.label) or Literal("")
    logger.debug("!!!!!!!!!!!!!! Here 5")
    content_value = g.value(text_uri, NS.cnt.chars)
    logger.debug("!!!!!!!!!!!!!! Here 6")
    logger.debug("g: %s", g)
    logger.debug("g.value: %s", g.value)
    logger.debug("text_uri: %s", text_uri)
    logger.debug("NS.cnt.chars: %s", NS.cnt.chars)
    logger.debug("content_value: %s", content_value)
    if content_value:
        content = sanitized_content(content_value)
        logger.debug("!!!!!!!!!!!!!! Here 6.1")
    else:
        content = ''
        logger.debug("!!!!!!!!!!!!!! Here 6.2")

    with transaction.commit_on_success():
        logger.debug("!!!!!!!!!!!!!! Here 7")
        for t in Text.objects.filter(identifier=t_uri, valid=True):
            logger.debug("!!!!!!!!!!!!!! Here 8")
            t.valid = False
            logger.debug("!!!!!!!!!!!!!! Here 9")
            t.save()
            logger.debug("!!!!!!!!!!!!!! Here 10")
            # While it looks like this would be better with a QuerySet update, we need to fire the save
            # events to keep the search index up to date. In all forseeable cases, this should only execute
            # for one Text object anyway.

        text = Text.objects.create(identifier=t_uri, title=title, content=content, last_user=user, project=p_uri)
        logger.debug("!!!!!!!!!!!!!! Here 11")

        project_g.add((text_uri, NS.rdf.type, NS.dctypes.Text))
        logger.debug("!!!!!!!!!!!!!! Here 12")
        project_g.set((text_uri, NS.dc.title, title))
        logger.debug("!!!!!!!!!!!!!! Here 13")
        project_g.set((text_uri, NS.rdfs.label, title))
        logger.debug("!!!!!!!!!!!!!! Here 14")

        text_url = URIRef(uris.url('semantic_store_project_texts', project_uri=p_uri, text_uri=text_uri))
        logger.debug("!!!!!!!!!!!!!! Here 15")
        project_g.set((text_uri, NS.ore.isDescribedBy, text_url))
        logger.debug("!!!!!!!!!!!!!! Here 16")

        if (URIRef(p_uri), NS.ore.aggregates, text_uri) in project_metadata_g:
            logger.debug("!!!!!!!!!!!!!! Here 16.1")
            project_metadata_g.add((text_uri, NS.rdf.type, NS.dctypes.Text))
            logger.debug("!!!!!!!!!!!!!! Here 16.2")
            project_metadata_g.set((text_uri, NS.dc.title, title))
            logger.debug("!!!!!!!!!!!!!! Here 16.3")
            project_metadata_g.set((text_uri, NS.rdfs.label, title))
            logger.debug("!!!!!!!!!!!!!! Here 16.4")

    logger.debug("!!!!!!!!!!!!!! Here 17")
    specific_resource_triples = specific_resources_subgraph(g, text_uri, p_uri)
    logger.debug("!!!!!!!!!!!!!! Here 18")
    for t in specific_resource_triples:
        logger.debug("!!!!!!!!!!!!!! Here 19")
        project_g.add(t)

    for t in g.triples((None, NS.rdf.type, NS.oa.TextQuoteSelector)):
        logger.debug("!!!!!!!!!!!!!! Here 20")
        project_g.set(t)