示例#1
0
文件: projects.py 项目: timandres/DM
def get_project_metadata_graph(project_uri):
    """
    Returns the database graph used as a cache to be returned when just the project contents overview is requested
    This should essentially contain the project title and description, what it aggregates, and just enough information
    for a GUI to render those contents (titles for texts, titles and image annos for canvases, etc.)
    """
    return Graph(store=rdfstore(), identifier=uris.project_metadata_graph_identifier(project_uri))
示例#2
0
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()
示例#3
0
def get_project_metadata_graph(project_uri):
    """
    Returns the database graph used as a cache to be returned when just the project contents overview is requested
    This should essentially contain the project title and description, what it aggregates, and just enough information
    for a GUI to render those contents (titles for texts, titles and image annos for canvases, etc.)
    """
    return Graph(store=rdfstore(), identifier=uris.project_metadata_graph_identifier(project_uri))
示例#4
0
def remove_canvas_triples(project_uri, canvas_uri, input_graph):
    project_graph = Graph(store=rdfstore(), identifier=canvas_identifier)
    project_metadata_g = Graph(rdfstore(), identifier=uris.project_metadata_graph_identifier(project_uri))

    removed_graph = Graph()

    for t in input_graph:
        if t in project_graph:
            project_graph.remove(t)
            project_metadata_g.remove(t)
            removed_graph.add(t)

    return removed_graph
示例#5
0
def update_canvas(project_uri, canvas_uri, input_graph):
    project_uri = URIRef(project_uri)
    canvas_uri = URIRef(canvas_uri)

    project_identifier = uris.uri('semantic_store_projects', uri=project_uri)
    project_graph = Graph(store=rdfstore(), identifier=project_identifier)
    project_metadata_g = Graph(rdfstore(), identifier=uris.project_metadata_graph_identifier(project_uri))

    if (canvas_uri, NS.dc.title, None) in input_graph:
        project_graph.remove((canvas_uri, NS.dc.title, None))
        project_metadata_g.remove((canvas_uri, NS.dc.title, None))
    if (canvas_uri, NS.rdfs.label, None) in input_graph:
        project_graph.remove((canvas_uri, NS.rdfs.label, None))
        project_metadata_g.remove((canvas_uri, NS.rdfs.label, None))

    project_graph += input_graph
    project_metadata_g += canvas_and_images_graph(input_graph, canvas_uri)

    return project_graph
示例#6
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)
示例#7
0
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()
示例#8
0
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)