Package org.dbpedia.spotlight.web.rest.output

Examples of org.dbpedia.spotlight.web.rest.output.Annotation


    // Annotation interface
    public Annotation process(String text, double confidence, int support, String ontologyTypesString,
                              String sparqlQuery, boolean blacklist, boolean coreferenceResolution, Spotter spotter, ParagraphDisambiguatorJ disambiguator)
            throws SearchException, ItemNotFoundException, InputException, SpottingException {

        Annotation annotation = new Annotation(text);
        List<Spot> spots = new LinkedList<Spot>();

        Text textObject = new Text(text);
        textObject.setFeature(new Score("confidence", confidence));

        if(Server.getTokenizer() != null)
            Server.getTokenizer().tokenizeMaybe(textObject);

        List<SurfaceFormOccurrence> entityMentions = spotter.extract(textObject);
        if (entityMentions.size()==0) return annotation; //nothing to disambiguate
        Paragraph paragraph = Factory.paragraph().fromJ(entityMentions);
        LOG.info(String.format("Spotted %d entity mentions.",entityMentions.size()));

        Map<SurfaceFormOccurrence,List<DBpediaResourceOccurrence>> entityCandidates = disambiguator.bestK(paragraph,k);
        LOG.info(String.format("Disambiguated %d candidates with %s.",entityCandidates.size(),disambiguator.name()));

        Enumeration.Value listColor = blacklist ? FilterPolicy$.MODULE$.Blacklist() : FilterPolicy$.MODULE$.Whitelist();

        /*The previous addition of filter to the Candidates requests (which has usability questioned) produce the error described at issue #136.
          To solve it, this feature for this argument (Candidates) is disabled, setting coreferenceResolution to false ever. Ignoring the user's configuration.
        */
        Boolean unableCoreferenceResolution = false;
        FilterElement filter = new OccsFilter(confidence, support, ontologyTypesString, sparqlQuery, blacklist, unableCoreferenceResolution, Server.getSimilarityThresholds(), Server.getSparqlExecute());

        Map<SurfaceFormOccurrence,List<DBpediaResourceOccurrence>> filteredEntityCandidates = new HashMap<SurfaceFormOccurrence,List<DBpediaResourceOccurrence>>();;

        for (Map.Entry<SurfaceFormOccurrence,List<DBpediaResourceOccurrence>> entry : entityCandidates.entrySet())
        {
            List<DBpediaResourceOccurrence> result = filter.accept(new FilterOccsImpl() ,entry.getValue());

            if (!result.isEmpty())
                filteredEntityCandidates.put(entry.getKey(), result);
        }

        for(SurfaceFormOccurrence sfOcc : filteredEntityCandidates.keySet()) {
            Spot spot = Spot.getInstance(sfOcc);
            List<Resource> resources = new LinkedList<Resource>();
            for(DBpediaResourceOccurrence occ : filteredEntityCandidates.get(sfOcc)) {
                Resource resource = Resource.getInstance(occ);
                resources.add(resource);
            }
            spot.setResources(resources);
            spots.add(spot);
        }
        annotation.setSpots(spots);
        return annotation;
    }
View Full Code Here


                           @Context HttpServletRequest request) {
        String clientIp = request.getRemoteAddr();

        try {
            String textToProcess = ServerUtils.getTextToProcess(text, inUrl);
            Annotation a = getAnnotation(textToProcess, confidence, support, dbpediaTypes, sparqlQuery, policy, coreferenceResolution, spotter, disambiguatorName, clientIp);
            LOG.info("XML format");
            String content = a.toXML();
            return ServerUtils.ok(content);
        } catch (Exception e) {
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). entity(e.getMessage()).type(MediaType.TEXT_XML).build());
        }
    }
View Full Code Here

                            @Context HttpServletRequest request) {
        String clientIp = request.getRemoteAddr();

        try {
            String textToProcess = ServerUtils.getTextToProcess(text, inUrl);
            Annotation a = getAnnotation(textToProcess, confidence, support, dbpediaTypes, sparqlQuery, policy, coreferenceResolution, spotter, disambiguatorName, clientIp);
            LOG.info("JSON format");
            String content = a.toJSON();
            return ServerUtils.ok(content);
        } catch (Exception e) {
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). entity(e.getMessage()).type(MediaType.APPLICATION_JSON).build());
        }
    }
View Full Code Here

        Spotter spotter = Server.getSpotter(spotterName);
        ParagraphDisambiguatorJ disambiguator = Server.getDisambiguator(disambiguatorName);

        /* Running Annotation */

        Annotation annotation = process(text, confidence, support, ontologyTypesString, sparqlQuery, blacklist, coreferenceResolution, spotter, disambiguator);

        LOG.debug("Shown: "+annotation.toXML());
        LOG.debug("****************************************************************");

        return annotation;
    }
View Full Code Here

        String clientIp = request.getRemoteAddr();

        try {
            String textToProcess = ServerUtils.getTextToProcess(text, inUrl);
            List<SurfaceFormOccurrence> spots = annotationInterface.spot(spotterName, new Text(textToProcess));
            String response = new Annotation(new Text(text), spots).toXML();
            return ServerUtils.ok(response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). entity(ServerUtils.print(e)).type(MediaType.TEXT_HTML).build());
        }
View Full Code Here

        String clientIp = request.getRemoteAddr();

        try {
            String textToProcess = ServerUtils.getTextToProcess(text, inUrl);
            List<SurfaceFormOccurrence> spots = annotationInterface.spot(spotterName, new Text(textToProcess));
            String response = new Annotation(new Text(text), spots).toJSON();
            return ServerUtils.ok(response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). entity(ServerUtils.print(e)).type(MediaType.TEXT_HTML).build());
        }
View Full Code Here

        String clientIp = request.getRemoteAddr();

        try {
            String textToProcess = ServerUtils.getTextToProcess(text, inUrl);
            List<SurfaceFormOccurrence> spots = annotationInterface.spot(spotterName, new Text(textToProcess));
            String response = new Annotation(new Text(text), spots).toXML();
            return ServerUtils.ok(response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). entity(ServerUtils.print(e)).type(MediaType.TEXT_HTML).build());
        }
View Full Code Here

        String clientIp = request.getRemoteAddr();

        try {
            String textToProcess = ServerUtils.getTextToProcess(text, inUrl);
            List<SurfaceFormOccurrence> spots = annotationInterface.spot(spotterName, new Text(text));
            String response = new Annotation(new Text(text), spots).toJSON();
            return ServerUtils.ok(response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST). entity(ServerUtils.print(e)).type(MediaType.TEXT_HTML).build());
        }
View Full Code Here

TOP

Related Classes of org.dbpedia.spotlight.web.rest.output.Annotation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.