Package org.dbpedia.spotlight.model

Examples of org.dbpedia.spotlight.model.DBpediaResource


        public DBpediaResource choose(ScoreDoc[] hits) throws SearchException {
            Map<DBpediaResource,Double> sumForResource = new HashMap<DBpediaResource,Double>();
            Map<DBpediaResource,Integer> countForResource = new HashMap<DBpediaResource,Integer>();
            // Iterate through the results:
            for (ScoreDoc hit : hits) {
                DBpediaResource r = this.searcher.getDBpediaResource(hit.doc);
                if (countForResource.containsKey(r)) {
                    countForResource.put(r, countForResource.get(r)+1);
                    sumForResource.put(r, sumForResource.get(r)+hit.score);
                } else {
                    countForResource.put(r, 1);
                    sumForResource.put(r, new Double(hit.score));
                }
            }
            for (Map.Entry<DBpediaResource,Double> entry: sumForResource.entrySet()) {
                DBpediaResource key = entry.getKey();
                Double sum = entry.getValue();
                Integer count = countForResource.get(key);
                sumForResource.put(key, sum/count);
            }
            return  maxAvg(sumForResource);
View Full Code Here


        while (parser.hasNext()) {
            Node[] triple = parser.next();
            if (triple[2].toString().equals(targetType)) {
                String targetUri = triple[0].toString().replace(SpotlightConfiguration.DEFAULT_NAMESPACE, "");
                try {
                    Set<SurfaceForm> surfaceFormsForURI = surrogateSearcher.getSurfaceForms(new DBpediaResource(targetUri));
                    for (SurfaceForm sf : surfaceFormsForURI) {
                        surfaceForms.add(sf.name());   
                    }
                }
                catch (SearchException e) {
View Full Code Here

        for (int i = 0; i< bindings.length(); i++) {
            JSONObject row = bindings.getJSONObject(i);
            for (int v = 0; v < vars.length(); v++) {
                JSONObject typeValue = row.getJSONObject((String) vars.get(v));
                String uri = typeValue.getString("value").replace(SpotlightConfiguration.DEFAULT_NAMESPACE, "");
                results.add(new DBpediaResource(uri));
            }
        }

        return results;
    }
View Full Code Here

        text= URLEncoder.encode(text, "utf-8");

        List<DBpediaResource> response = c.extract(new Text(text));

        DBpediaResource[] expectedEntities = {new DBpediaResource("Son"), new  DBpediaResource("Pedro_I_of_Brazil"), new  DBpediaResource("Territory_%28administrative_division%29"), new  DBpediaResource("Brazil"), new  DBpediaResource("Monarchy"), new  DBpediaResource("Father"), new  DBpediaResource("Governance"), new  DBpediaResource("Pedro_I_of_Brazil"), new  DBpediaResource("Wars_of_succession"), new  DBpediaResource("Empire_of_Brazil"), new  DBpediaResource("Pedro_II_of_Brazil"), new  DBpediaResource("Brazilian_Declaration_of_Independence"), new  DBpediaResource("Politics_of_the_Empire_of_Brazil"), new  DBpediaResource("Constitutional_monarchy"), new  DBpediaResource("October"), new  DBpediaResource("September"), new  DBpediaResource("Emperor"), new  DBpediaResource("Nation"), new  DBpediaResource("Government")};
        //TODO sort and compare
        assertEquals(Arrays.asList(expectedEntities).size(),response.size());

    }
View Full Code Here

        while (nxParser.hasNext()) {
            Node[] nodes = nxParser.next();
            String resourceString = nodes[0].toString().replace(SpotlightConfiguration.DEFAULT_NAMESPACE,"");
            String surfaceFormString = nodes[2].toString();
            List<SurfaceForm> surfaceForms = AddSurfaceFormsToIndex.fromTitlesToAlternativesJ(new SurfaceForm(surfaceFormString));
            add(surfaceForms, new DBpediaResource(resourceString));
        }

        LOG.info("Done.");
    }
View Full Code Here

            String[] line = tsvScanner.nextLine().split(separator);
            String surfaceFormString = line[0];
            String resourceString = line[1];
            //TODO read counts and set DBpediaResource.support
            // int countSfRes = new Integer(line[2])
            DBpediaResource res = new DBpediaResource(resourceString);
            // DBpediaResource res = new DBpediaResource(resourceString,countSfRes)
            List<SurfaceForm> surfaceForms = AddSurfaceFormsToIndex.fromTitlesToAlternativesJ(new SurfaceForm(surfaceFormString));
            add(surfaceForms, res);
        }
View Full Code Here

            String countAndSf = line[0];
            int count = Integer.valueOf(countAndSf.substring(0,7).trim());
            String resourceString = countAndSf.substring(8);
            String surfaceFormString = line[1];
            if (count>minCount)
                add(new SurfaceForm(surfaceFormString), new DBpediaResource(resourceString), count);
                List<SurfaceForm> surfaceForms = AddSurfaceFormsToIndex.fromTitlesToAlternativesJ(new SurfaceForm(surfaceFormString));
                add(surfaceForms, new DBpediaResource(resourceString));
            } catch(ArrayIndexOutOfBoundsException e) {
                LOG.error("Error parsing line: "+line);
                e.printStackTrace();
            }
        }
View Full Code Here

            int numUpdatedDocs = 0;
            for(String uri: uriToDocumentMap.keySet()) {               
                // Get document from buffer
                Document docForResource = uriToDocumentMap.get(uri);
                // Merge with documents from disk if there are any
                List<Document> occurrences = searcher.getOccurrences(new DBpediaResource(uri));
                for (Document occurrenceDoc: occurrences) {
                    docForResource = mLucene.merge(occurrenceDoc, docForResource); // adds occurrence to resource
                }
                // If no merges were needed, add document
                if (occurrences.size() == 0) {
View Full Code Here

TOP

Related Classes of org.dbpedia.spotlight.model.DBpediaResource

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.