Exemple #1
0
def get_response(project_uri, query_string, include_n3=True):
    d = {
        'results': list(),
    }

    project_graph = projects.get_project_graph(project_uri)
    graph = Graph()

    query_set = SearchQuerySet().models(Text).filter(
        content=AutoQuery(query_string), project__exact=project_uri
    )

    highlighter = Highlighter(query_string, html_tag='span', css_class=CSS_RESULT_MATCH_CLASS)
    title_highlighter = TitleHighlighter(query_string, html_tag='span', css_class=CSS_RESULT_MATCH_CLASS)

    d['spelling_suggestion'] = query_set.spelling_suggestion()

    for result in query_set:
        text_uri = URIRef(result.get_stored_fields()['identifier'])

        if annotations.has_annotation_link(project_graph, text_uri) or projects.is_top_level_project_resource(project_uri, text_uri):
            d['results'].append(search_result_to_dict(result, project_uri, highlighter, title_highlighter))

            if include_n3:
                graph += utils.metadata_triples(project_graph, text_uri)

    if include_n3:
        d['n3'] = graph.serialize(format='n3')

    return d
Exemple #2
0
    def post(self, request, project_uri):    
        project_uri = URIRef(project_uri)
        project_graph = get_project_graph(project_uri)
        project_metadata_graph = get_project_metadata_graph(project_uri)
        canvas_graph = Graph()

        image_file = request.FILES['image_file']
        title = request.POST.get('title', '')
        uri = uris.uuid()

        if hasattr(settings, 'MAX_IMAGE_UPLOAD_FILE_SIZE') and image_file.size > settings.MAX_IMAGE_UPLOAD_FILE_SIZE:
            return HttpResponse(status=406)
        if not image_file.content_type.startswith('image/'):
            return HttpResponse(status=406)

        uploaded = UploadedImage.objects.create(imagefile=image_file, owner=request.user)
        create_canvas_from_upload(canvas_graph, uploaded, uri, request.user, title)

        # Make the canvas a top level project resource
        canvas_graph.add((project_uri, NS.ore.aggregates, uri))

        project_graph += canvas_graph
        project_metadata_graph += canvas_graph

        canvas_graph += metadata_triples(project_metadata_graph, project_uri)
        canvas_graph += project_metadata_graph.triples((project_uri, NS.ore.aggregates, None))

        return NegotiatedGraphResponse(request, canvas_graph)
Exemple #3
0
    def post(self, request, project_uri):
        project_uri = URIRef(project_uri)
        project_graph = get_project_graph(project_uri)
        project_metadata_graph = get_project_metadata_graph(project_uri)
        canvas_graph = Graph()

        image_file = request.FILES['image_file']
        title = request.POST.get('title', '')
        uri = uris.uuid()

        if hasattr(settings, 'MAX_IMAGE_UPLOAD_FILE_SIZE'
                   ) and image_file.size > settings.MAX_IMAGE_UPLOAD_FILE_SIZE:
            return HttpResponse(status=406)
        if not image_file.content_type.startswith('image/'):
            return HttpResponse(status=406)

        uploaded = UploadedImage.objects.create(imagefile=image_file,
                                                owner=request.user)
        create_canvas_from_upload(canvas_graph, uploaded, uri, request.user,
                                  title)

        # Make the canvas a top level project resource
        canvas_graph.add((project_uri, NS.ore.aggregates, uri))

        project_graph += canvas_graph
        project_metadata_graph += canvas_graph

        canvas_graph += metadata_triples(project_metadata_graph, project_uri)
        canvas_graph += project_metadata_graph.triples(
            (project_uri, NS.ore.aggregates, None))

        return NegotiatedGraphResponse(request, canvas_graph)
Exemple #4
0
    def get(self, request, project_uri, canvas_uri, transcription_uri):
        project_uri = URIRef(project_uri)
        canvas_uri = URIRef(canvas_uri)

        if transcription_uri:
            transcription_uri = URIRef(transcription_uri)

            project_graph = get_project_graph(project_uri)

            return NegotiatedGraphResponse(request, resource_annotation_subgraph(project_graph, transcription_uri))
Exemple #5
0
    def manuscript_graph(self, manuscript_uri, project_uri):
        project_graph = get_project_graph(project_uri)
        subgraph = manuscripts.manuscript_subgraph(project_graph, manuscript_uri)

        for canvas in subgraph.subjects(NS.rdf.type, NS.sc.Canvas):
            if (canvas, NS.ore.isDescribedBy, None) not in subgraph:
                canvas_url = uris.url('semantic_store_project_canvases', project_uri=project_uri, canvas_uri=canvas)
                subgraph.add((canvas, NS.ore.isDescribedBy, canvas_url))

        return subgraph
Exemple #6
0
    def get(self, request, project_uri, canvas_uri, transcription_uri):
        project_uri = URIRef(project_uri)
        canvas_uri = URIRef(canvas_uri)

        if transcription_uri:
            transcription_uri = URIRef(transcription_uri)

            project_graph = get_project_graph(project_uri)

            return NegotiatedGraphResponse(
                request,
                resource_annotation_subgraph(project_graph, transcription_uri))
Exemple #7
0
    def manuscript_graph(self, manuscript_uri, project_uri):
        project_graph = get_project_graph(project_uri)
        subgraph = manuscripts.manuscript_subgraph(project_graph,
                                                   manuscript_uri)

        for canvas in subgraph.subjects(NS.rdf.type, NS.sc.Canvas):
            if (canvas, NS.ore.isDescribedBy, None) not in subgraph:
                canvas_url = uris.url('semantic_store_project_canvases',
                                      project_uri=project_uri,
                                      canvas_uri=canvas)
                subgraph.add((canvas, NS.ore.isDescribedBy, canvas_url))

        return subgraph
Exemple #8
0
    def get(self, request, project_uri, manuscript_uri=None):
        project_uri = URIRef(project_uri)

        project_graph = get_project_graph(project_uri)

        if manuscript_uri:
            manuscript_uri = URIRef(manuscript_uri)
            return NegotiatedGraphResponse(request, self.manuscript_graph(manuscript_uri, project_uri))
        else:
            graph = Graph()

            for manuscript in project_graph.subjects(NS.rdf.type, NS.sc.Manifest):
                graph += self.manuscript_graph(manuscript, project_uri)

            return NegotiatedGraphResponse(request, graph)
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Don't use "from appname.models import ModelName".
        # Use orm.ModelName to refer to models in this application,
        # and orm['appname.ModelName'] for models in other applications.

        from semantic_store.projects import get_project_graph
        from semantic_store.namespaces import NS

        for permission in orm.ProjectPermission.objects.filter(permission='r'):
            project_uri = permission.identifier
            project_graph = get_project_graph(project_uri)
            for text_uri in project_graph.subjects(NS.rdf.type,
                                                   NS.dcmitype.Text):
                for text in orm.Text.objects.filter(identifier=text_uri):
                    text.project = project_uri
                    text.save()
Exemple #10
0
    def get(self, request, project_uri, manuscript_uri=None):
        project_uri = URIRef(project_uri)

        project_graph = get_project_graph(project_uri)

        if manuscript_uri:
            manuscript_uri = URIRef(manuscript_uri)
            return NegotiatedGraphResponse(
                request, self.manuscript_graph(manuscript_uri, project_uri))
        else:
            graph = Graph()

            for manuscript in project_graph.subjects(NS.rdf.type,
                                                     NS.sc.Manifest):
                graph += self.manuscript_graph(manuscript, project_uri)

            return NegotiatedGraphResponse(request, graph)
Exemple #11
0
    def get(self, request, project_uri, extension):
        format = 'turtle' if extension.lower() == 'ttl' else extension
        if format not in RDFLIB_SERIALIZER_FORMATS:
            return HttpResponseBadRequest()

        project_uri = URIRef(project_uri)
        db_project_graph = get_project_graph(project_uri)

        def serialization_iterator(project_uri, format):
            yield ''
            export_graph = project_export_graph(project_uri)
            bind_namespaces(export_graph)
            yield export_graph.serialize(format=format)

        project_title = get_title(db_project_graph, project_uri) or u'untitled project'

        response = StreamingHttpResponse(serialization_iterator(project_uri, format), mimetype='text/%s' % extension)
        response['Content-Disposition'] = 'attachment; filename=%s.%s' % (slugify(project_title), extension)

        return response
Exemple #12
0
def get_response(project_uri, query_string, include_n3=True):
    d = {
        'results': list(),
    }

    project_graph = projects.get_project_graph(project_uri)
    graph = Graph()

    query_set = SearchQuerySet().models(Text).filter(
        content=AutoQuery(query_string), project__exact=project_uri)

    highlighter = Highlighter(query_string,
                              html_tag='span',
                              css_class=CSS_RESULT_MATCH_CLASS)
    title_highlighter = TitleHighlighter(query_string,
                                         html_tag='span',
                                         css_class=CSS_RESULT_MATCH_CLASS)

    d['spelling_suggestion'] = query_set.spelling_suggestion()

    for result in query_set:
        text_uri = URIRef(result.get_stored_fields()['identifier'])

        if annotations.has_annotation_link(
                project_graph,
                text_uri) or projects.is_top_level_project_resource(
                    project_uri, text_uri):
            d['results'].append(
                search_result_to_dict(result, project_uri, highlighter,
                                      title_highlighter))

            if include_n3:
                graph += utils.metadata_triples(project_graph, text_uri)

    if include_n3:
        d['n3'] = graph.serialize(format='n3')

    return d
Exemple #13
0
    def get(self, request, project_uri, extension):
        format = 'turtle' if extension.lower() == 'ttl' else extension
        if format not in RDFLIB_SERIALIZER_FORMATS:
            return HttpResponseBadRequest()

        project_uri = URIRef(project_uri)
        db_project_graph = get_project_graph(project_uri)

        def serialization_iterator(project_uri, format):
            yield ''
            export_graph = project_export_graph(project_uri)
            bind_namespaces(export_graph)
            yield export_graph.serialize(format=format)

        project_title = get_title(db_project_graph,
                                  project_uri) or u'untitled project'

        response = StreamingHttpResponse(serialization_iterator(
            project_uri, format),
                                         mimetype='text/%s' % extension)
        response['Content-Disposition'] = 'attachment; filename=%s.%s' % (
            slugify(project_title), extension)

        return response