Package com.google.refine.model

Examples of com.google.refine.model.Recon


            Judgment oldJudgment = cell.recon == null ? Judgment.None : cell.recon.judgment;

            newCell = new Cell(
                cell.value,
                cell.recon == null ? new Recon(historyEntryID, identifierSpace, schemaSpace) : cell.recon.dup(historyEntryID)
            );

            String cellDescription =
                "single cell on row " + (rowIndex + 1) +
                ", column " + column.getName() +
View Full Code Here


                String s = ParsingUtilities.inputStreamToString(is);
                JSONObject o = ParsingUtilities.evaluateJsonStringToObject(s);
               
                for (int i = 0; i < jobs.size(); i++) {
                    StandardReconJob job = (StandardReconJob) jobs.get(i);
                    Recon recon = null;
                   
                    String text = job.text;
                    String key = "q" + i;
                    if (o.has(key)) {
                        JSONObject o2 = o.getJSONObject(key);
                        if (o2.has("result")) {
                            JSONArray results = o2.getJSONArray("result");
                           
                            recon = createReconServiceResults(text, results, historyEntryID);
                        } else {
                            logger.warn("Service error for text: " + text + "\n  Job code: " + job.code + "\n  Response: " + o2.toString());
                        }
                    } else {
                        logger.warn("Service error for text: " + text + "\n  Job code: " + job.code);
                    }
                   
                    if (recon != null) {
                        recon.service = service;
                    }
                    recons.add(recon);
                }
            } finally {
                is.close();
            }
//        } catch (IOException e) {
//            // TODO: Retry on HTTP 500 errors?
        } catch (Exception e) {
            logger.error("Failed to batch recon with load:\n" + queriesString, e);
        }
       
        while (recons.size() < jobs.size()) {
            Recon recon = new Recon(historyEntryID, identifierSpace, schemaSpace);
            recon.service = service;
            recon.identifierSpace = identifierSpace;
            recon.schemaSpace = schemaSpace;

            recons.add(recon);
View Full Code Here

        return recons;
    }
   
    @Override
    public Recon createNewRecon(long historyEntryID) {
        Recon recon = new Recon(historyEntryID, identifierSpace, schemaSpace);
        recon.service = service;
        return recon;
    }
View Full Code Here

        recon.service = service;
        return recon;
    }

    protected Recon createReconServiceResults(String text, JSONArray results, long historyEntryID) {
        Recon recon = new Recon(historyEntryID, identifierSpace, schemaSpace);
        try {
            int length = results.length();
            int count = 0;
            for (int i = 0; i < length && count < 3; i++) {
                JSONObject result = results.getJSONObject(i);
                if (!result.has("name")) {
                    continue;
                }
               
                JSONArray types = result.getJSONArray("type");
                String[] typeIDs = new String[types.length()];
                for (int j = 0; j < typeIDs.length; j++) {
                    Object type = types.get(j);
                    typeIDs[j] = type instanceof String ? (String) type :
                        ((JSONObject) type).getString("id");
                }
               
                double score = result.getDouble("score");
                ReconCandidate candidate = new ReconCandidate(
                    result.getString("id"),
                    result.getString("name"),
                    typeIDs,
                    score
                );
               
                if (autoMatch && i == 0 && result.has("match") && result.getBoolean("match")) {
                    recon.match = candidate;
                    recon.matchRank = 0;
                    recon.judgment = Judgment.Matched;
                    recon.judgmentAction = "auto";
                }
               
                recon.addCandidate(candidate);
                count++;
            }
           
            if (count > 0) {
                ReconCandidate candidate = recon.candidates.get(0);
               
                recon.setFeature(Recon.Feature_nameMatch, text.equalsIgnoreCase(candidate.name));
                recon.setFeature(Recon.Feature_nameLevenshtein,
                        StringUtils.getLevenshteinDistance(StringUtils.lowerCase(text), StringUtils.lowerCase(candidate.name)));
                recon.setFeature(Recon.Feature_nameWordDistance, wordDistance(text, candidate.name));
               
                recon.setFeature(Recon.Feature_typeMatch, false);
                if (this.typeID != null) {
                    for (String typeID : candidate.types) {
                        if (this.typeID.equals(typeID)) {
                            recon.setFeature(Recon.Feature_typeMatch, true);
                            break;
                        }
                    }
                }
            }
View Full Code Here

    static protected Cell extractCell(OdfTableCell cell, Map<String, Recon> reconMap) {
        Serializable value = extractCell(cell);

        if (value != null) {
            Recon recon = null;

            String hyperlink = ""; // TODO: cell.getHyperlink();
            if (hyperlink != null) {
                String url = hyperlink; // TODO: hyperlink.getAddress();

                if (url.startsWith("http://") ||
                        url.startsWith("https://")) {

                    final String sig = "freebase.com/view";

                    int i = url.indexOf(sig);
                    if (i > 0) {
                        String id = url.substring(i + sig.length());

                        int q = id.indexOf('?');
                        if (q > 0) {
                            id = id.substring(0, q);
                        }
                        int h = id.indexOf('#');
                        if (h > 0) {
                            id = id.substring(0, h);
                        }

                        if (reconMap.containsKey(id)) {
                            recon = reconMap.get(id);
                            recon.judgmentBatchSize++;
                        } else {
                            recon = new Recon(0, null, null);
                            recon.service = "import";
                            recon.match = new ReconCandidate(id, value.toString(), new String[0], 100);
                            recon.matchRank = 0;
                            recon.judgment = Judgment.Matched;
                            recon.judgmentAction = "auto";
                            recon.judgmentBatchSize = 1;
                            recon.addCandidate(recon.match);

                            reconMap.put(id, recon);
                        }
                    }
                }
View Full Code Here

                                result.getString("name"),
                                typeIDs,
                                100
                        );

                        Recon recon = Recon.makeFreebaseRecon(historyEntryID);
                        recon.addCandidate(candidate);
                        recon.service = "mql";
                        recon.judgment = Judgment.Matched;
                        recon.judgmentAction = "auto";
                        recon.match = candidate;
                        recon.matchRank = 0;

                        idToRecon.put(id, recon);
                    }
                }
            } finally {
                is.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (ReconJob job : jobs) {
            String id = ((IdBasedReconJob) job).id;
            Recon recon = idToRecon.get(id);
            if (recon == null) {
                recon = createNoMatchRecon(historyEntryID);
            }
            recons.add(recon);
        }
View Full Code Here

                                result.getString("name"),
                                typeIDs,
                                100
                        );

                        Recon recon = Recon.makeFreebaseRecon(historyEntryID);
                        recon.addCandidate(candidate);
                        recon.service = "mql";
                        recon.judgment = Judgment.Matched;
                        recon.judgmentAction = "auto";
                        recon.match = candidate;
                        recon.matchRank = 0;

                        keyToRecon.put(key, recon);
                    }
                }
            } finally {
                is.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (ReconJob job : jobs) {
            String key = ((KeyBasedReconJob) job).key;
            Recon recon = keyToRecon.get(key);
            if (recon == null) {
                recon = createNoMatchRecon(historyEntryID);
            }
            recons.add(recon);
        }
View Full Code Here

    public Recon createNewRecon(long historyEntryID) {
        return Recon.makeFreebaseRecon(historyEntryID);
    }
   
    protected Recon createNoMatchRecon(long historyEntryID) {
        Recon recon = createNewRecon(historyEntryID);
        recon.service = "mql";
        recon.judgment = Judgment.None;
        recon.matchRank = -1;
        return recon;
    }
View Full Code Here

            Object value = values[c];
            Cell cell = null;
           
            if (value instanceof ReconCandidate) {
                ReconCandidate rc = (ReconCandidate) value;
                Recon recon;
                if (reconMap.containsKey(rc.id)) {
                    recon = reconMap.get(rc.id);
                } else {
                    recon = Recon.makeFreebaseRecon(_historyEntryID);
                    recon.addCandidate(rc);
                    recon.service = "mql";
                    recon.match = rc;
                    recon.matchRank = 0;
                    recon.judgment = Judgment.Matched;
                    recon.judgmentAction = "auto";
View Full Code Here

            Row row = project.rows.get(r);
           
            for (int c = 0; c < row.cells.size(); c++) {
                Cell cell = row.cells.get(c);
                if (cell != null && cell.recon != null) {
                    Recon oldRecon = cell.recon;
                   
                    if (reconIDToResult.containsKey(oldRecon.id)) {
                        Recon newRecon = oldRecon.dup();
                        newRecon.setFeature(Recon.Feature_qaResult, reconIDToResult.get(oldRecon.id));
                       
                        reconIDToResult.remove(oldRecon.id);
                       
                        oldRecons.put(oldRecon.id, oldRecon);
                        newRecons.put(oldRecon.id, newRecon);
View Full Code Here

TOP

Related Classes of com.google.refine.model.Recon

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.