Example usage for com.fasterxml.jackson.databind JsonNode size

List of usage examples for com.fasterxml.jackson.databind JsonNode size

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode size.

Prototype

public int size() 

Source Link

Usage

From source file:com.betfair.cougar.test.socket.app.SocketCompatibilityTestingApp.java

public static void main(String[] args) throws Exception {

    Parser parser = new PosixParser();
    Options options = new Options();
    options.addOption("r", "repo", true, "Repository type to search: local|central");
    options.addOption("c", "client-concurrency", true,
            "Max threads to allow each client tester to run tests, defaults to 10");
    options.addOption("t", "test-concurrency", true, "Max client testers to run concurrently, defaults to 5");
    options.addOption("m", "max-time", true,
            "Max time (in minutes) to allow tests to complete, defaults to 10");
    options.addOption("v", "version", false, "Print version and exit");
    options.addOption("h", "help", false, "This help text");
    CommandLine commandLine = parser.parse(options, args);
    if (commandLine.hasOption("h")) {
        System.out.println(options);
        System.exit(0);/* w  ww  .j a v  a 2 s  .co  m*/
    }
    if (commandLine.hasOption("v")) {
        System.out.println("How the hell should I know?");
        System.exit(0);
    }
    // 1. Find all testers in given repos
    List<RepoSearcher> repoSearchers = new ArrayList<>();
    for (String repo : commandLine.getOptionValues("r")) {
        if ("local".equals(repo.toLowerCase())) {
            repoSearchers.add(new LocalRepoSearcher());
        } else if ("central".equals(repo.toLowerCase())) {
            repoSearchers.add(new CentralRepoSearcher());
        } else {
            System.err.println("Unrecognized repo: " + repo);
            System.err.println(options);
            System.exit(1);
        }
    }
    int clientConcurrency = 10;
    if (commandLine.hasOption("c")) {
        try {
            clientConcurrency = Integer.parseInt(commandLine.getOptionValue("c"));
        } catch (NumberFormatException nfe) {
            System.err.println(
                    "client-concurrency is not a valid integer: '" + commandLine.getOptionValue("c") + "'");
            System.exit(1);
        }
    }
    int testConcurrency = 5;
    if (commandLine.hasOption("t")) {
        try {
            testConcurrency = Integer.parseInt(commandLine.getOptionValue("t"));
        } catch (NumberFormatException nfe) {
            System.err.println(
                    "test-concurrency is not a valid integer: '" + commandLine.getOptionValue("t") + "'");
            System.exit(1);
        }
    }
    int maxMinutes = 10;
    if (commandLine.hasOption("m")) {
        try {
            maxMinutes = Integer.parseInt(commandLine.getOptionValue("m"));
        } catch (NumberFormatException nfe) {
            System.err.println("max-time is not a valid integer: '" + commandLine.getOptionValue("m") + "'");
            System.exit(1);
        }
    }

    Properties clientProps = new Properties();
    clientProps.setProperty("client.concurrency", String.valueOf(clientConcurrency));

    File baseRunDir = new File(System.getProperty("user.dir") + "/run");
    baseRunDir.mkdirs();

    File tmpDir = new File(baseRunDir, "jars");
    tmpDir.mkdirs();

    List<ServerRunner> serverRunners = new ArrayList<>();
    List<ClientRunner> clientRunners = new ArrayList<>();
    for (RepoSearcher searcher : repoSearchers) {
        List<File> jars = searcher.findAndCache(tmpDir);
        for (File f : jars) {
            ServerRunner serverRunner = new ServerRunner(f, baseRunDir);
            System.out.println("Found tester: " + serverRunner.getVersion());
            serverRunners.add(serverRunner);
            clientRunners.add(new ClientRunner(f, baseRunDir, clientProps));
        }
    }

    // 2. Start servers and collect ports
    System.out.println();
    System.out.println("Starting " + serverRunners.size() + " servers...");
    for (ServerRunner server : serverRunners) {
        server.startServer();
    }
    System.out.println();

    List<TestCombo> tests = new ArrayList<>(serverRunners.size() * clientRunners.size());
    for (ServerRunner server : serverRunners) {
        for (ClientRunner client : clientRunners) {
            tests.add(new TestCombo(server, client));
        }
    }

    System.out.println("Enqueued " + tests.size() + " test combos to run...");

    long startTime = System.currentTimeMillis();
    // 3. Run every client against every server, collecting results
    BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue(serverRunners.size() * clientRunners.size());
    ThreadPoolExecutor service = new ThreadPoolExecutor(testConcurrency, testConcurrency, 5000,
            TimeUnit.MILLISECONDS, workQueue);
    service.prestartAllCoreThreads();
    workQueue.addAll(tests);
    while (!workQueue.isEmpty()) {
        Thread.sleep(1000);
    }
    service.shutdown();
    service.awaitTermination(maxMinutes, TimeUnit.MINUTES);
    long endTime = System.currentTimeMillis();
    long totalTimeSecs = Math.round((endTime - startTime) / 1000.0);
    for (ServerRunner server : serverRunners) {
        server.shutdownServer();
    }

    System.out.println();
    System.out.println("=======");
    System.out.println("Results");
    System.out.println("-------");
    // print a summary
    int totalTests = 0;
    int totalSuccess = 0;
    for (TestCombo combo : tests) {
        String clientVer = combo.getClientVersion();
        String serverVer = combo.getServerVersion();
        String results = combo.getClientResults();
        ObjectMapper mapper = new ObjectMapper(new JsonFactory());
        JsonNode node = mapper.reader().readTree(results);
        JsonNode resultsArray = node.get("results");
        int numTests = resultsArray.size();
        int numSuccess = 0;
        for (int i = 0; i < numTests; i++) {
            if ("success".equals(resultsArray.get(i).get("result").asText())) {
                numSuccess++;
            }
        }
        totalSuccess += numSuccess;
        totalTests += numTests;
        System.out.println(clientVer + "/" + serverVer + ": " + numSuccess + "/" + numTests
                + " succeeded - took " + String.format("%2f", combo.getRunningTime()) + " seconds");
    }
    System.out.println("-------");
    System.out.println(
            "Overall: " + totalSuccess + "/" + totalTests + " succeeded - took " + totalTimeSecs + " seconds");

    FileWriter out = new FileWriter("results.json");
    PrintWriter pw = new PrintWriter(out);

    // 4. Output full results
    pw.println("{\n  \"results\": [");
    for (TestCombo combo : tests) {
        combo.emitResults(pw, "    ");
    }
    pw.println("  ],");
    pw.println("  \"servers\": [");
    for (ServerRunner server : serverRunners) {
        server.emitInfo(pw, "    ");
    }
    pw.println("  ],");
    pw.close();
}

From source file:au.org.ands.vocabs.toolkit.db.PopulateAccessPoints.java

/**
 * Main program./*from   w  w  w . j  ava 2s  .  c  o  m*/
 * @param args Command-line arguments
 */
public static void main(final String[] args) {
    // Create prefixes that both end with a slash, so that
    // they can be substituted for each other.
    String sparqlPrefix = sparqlPrefixProperty;
    if (!sparqlPrefix.endsWith("/")) {
        sparqlPrefix += "/";
    }
    String sesamePrefix = sesamePrefixProperty;
    if (!sesamePrefix.endsWith("/")) {
        sesamePrefix += "/";
    }
    sesamePrefix += "repositories/";
    System.out.println("sparqlPrefix: " + sparqlPrefix);
    System.out.println("sesamePrefix: " + sesamePrefix);
    List<Version> versions = VersionUtils.getAllVersions();
    for (Version version : versions) {
        System.out.println(version.getId());
        System.out.println(version.getTitle());
        String data = version.getData();
        System.out.println(data);
        JsonNode dataJson = TaskUtils.jsonStringToTree(data);
        JsonNode accessPoints = dataJson.get("access_points");
        if (accessPoints != null) {
            System.out.println(accessPoints);
            System.out.println(accessPoints.size());
            for (JsonNode accessPoint : accessPoints) {
                System.out.println(accessPoint);
                AccessPoint ap = new AccessPoint();
                ap.setVersionId(version.getId());
                String type = accessPoint.get("type").asText();
                JsonObjectBuilder jobPortal = Json.createObjectBuilder();
                JsonObjectBuilder jobToolkit = Json.createObjectBuilder();
                String uri;
                switch (type) {
                case AccessPoint.FILE_TYPE:
                    ap.setType(type);
                    // Get the path from the original access point.
                    String filePath = accessPoint.get("uri").asText();
                    // Save the last component of the path to use
                    // in the portal URI.
                    String downloadFilename = Paths.get(filePath).getFileName().toString();
                    if (!filePath.startsWith("/")) {
                        // Relative path that we need to fix up manually.
                        filePath = "FIXME " + filePath;
                    }
                    jobToolkit.add("path", filePath);
                    ap.setPortalData("");
                    ap.setToolkitData(jobToolkit.build().toString());
                    // Persist what we have ...
                    AccessPointUtils.saveAccessPoint(ap);
                    // ... so that now we can get access to the
                    // ID of the persisted object with ap2.getId().
                    String format;
                    if (downloadFilename.endsWith(".trig")) {
                        // Force TriG. This is needed for some legacy
                        // cases where the filename is ".trig" but
                        // the format has been incorrectly recorded
                        // as RDF/XML.
                        format = "TriG";
                    } else {
                        format = accessPoint.get("format").asText();
                    }
                    jobPortal.add("format", format);
                    jobPortal.add("uri", downloadPrefixProperty + ap.getId() + "/" + downloadFilename);
                    ap.setPortalData(jobPortal.build().toString());
                    AccessPointUtils.updateAccessPoint(ap);
                    break;
                case AccessPoint.API_SPARQL_TYPE:
                    ap.setType(type);
                    uri = accessPoint.get("uri").asText();
                    jobPortal.add("uri", uri);
                    if (uri.startsWith(sparqlPrefix)) {
                        // One of ours, so also add a sesameDownload
                        // endpoint.
                        AccessPoint ap2 = new AccessPoint();
                        ap2.setVersionId(version.getId());
                        ap2.setType(AccessPoint.SESAME_DOWNLOAD_TYPE);
                        ap2.setPortalData("");
                        ap2.setToolkitData("");
                        // Persist what we have ...
                        AccessPointUtils.saveAccessPoint(ap2);
                        // ... so that now we can get access to the
                        // ID of the persisted object with ap2.getId().
                        JsonObjectBuilder job2Portal = Json.createObjectBuilder();
                        JsonObjectBuilder job2Toolkit = Json.createObjectBuilder();
                        job2Portal.add("uri", downloadPrefixProperty + ap2.getId() + "/"
                                + Download.downloadFilename(ap2, ""));
                        job2Toolkit.add("uri", uri.replaceFirst(sparqlPrefix, sesamePrefix));
                        ap2.setPortalData(job2Portal.build().toString());
                        ap2.setToolkitData(job2Toolkit.build().toString());
                        AccessPointUtils.updateAccessPoint(ap2);
                        jobPortal.add("source", AccessPoint.SYSTEM_SOURCE);
                    } else {
                        jobPortal.add("source", AccessPoint.USER_SOURCE);
                    }
                    ap.setPortalData(jobPortal.build().toString());
                    ap.setToolkitData(jobToolkit.build().toString());
                    AccessPointUtils.saveAccessPoint(ap);
                    break;
                case AccessPoint.WEBPAGE_TYPE:
                    uri = accessPoint.get("uri").asText();
                    if (uri.endsWith("concept/topConcepts")) {
                        ap.setType(AccessPoint.SISSVOC_TYPE);
                        jobPortal.add("source", AccessPoint.SYSTEM_SOURCE);
                        jobPortal.add("uri", uri.replaceFirst("/concept/topConcepts$", ""));
                    } else {
                        ap.setType(type);
                        jobPortal.add("uri", uri);
                    }
                    ap.setPortalData(jobPortal.build().toString());
                    ap.setToolkitData(jobToolkit.build().toString());
                    AccessPointUtils.saveAccessPoint(ap);
                    break;
                default:
                }
                System.out.println("type is: " + ap.getType());
                System.out.println("portal_data: " + ap.getPortalData());
                System.out.println("toolkit_data: " + ap.getToolkitData());
            }
        }
    }
}

From source file:json_cmp.Comparer.java

public static void main(String[] args) {
    System.out.println("Testing Begin");
    try {/*  w  w  w .j  av a 2s.  co m*/

        String accessLogFolder = "/Users/herizhao/workspace/accessLog/";
        //        String yqlFileName = "json_cmp/test1.log";
        //        String yqlpFileName = "json_cmp/test2.log";
        String yqlFileName = "tempLog/0812_yql.res";
        String yqlpFileName = "tempLog/0812_yqlp.res";
        ReadResults input1 = new ReadResults(accessLogFolder + yqlFileName);
        ReadResults input2 = new ReadResults(accessLogFolder + yqlpFileName);
        Integer diffNum = 0;
        Integer errorCount = 0;
        Integer totalIDNum1 = 0;
        Integer totalIDNum2 = 0;
        Integer equalIDwithDuplicate = 0;
        Integer beacons = 0;
        Integer lineNum = 0;
        Integer tempCount = 0;
        HashMap<String, IDclass> IDarray = new HashMap<String, IDclass>();
        FileOutputStream fos = new FileOutputStream(
                "/Users/herizhao/workspace/accessLog/json_cmp/cmp_result.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        FileOutputStream consoleStream = new FileOutputStream(
                "/Users/herizhao/workspace/accessLog/json_cmp/console");
        OutputStreamWriter consoleOSW = new OutputStreamWriter(consoleStream);
        BufferedWriter console = new BufferedWriter(consoleOSW);
        while (true) {
            input1.ReadNextLine();
            if (input1.line == null)
                break;
            input2.ReadNextLine();
            if (input2.line == null)
                break;
            while (input1.line.equals("")) {
                lineNum++;
                input1.ReadNextLine();
                input2.ReadNextLine();
            }
            if (input2.line == null)
                break;
            if (input1.line == null)
                break;
            lineNum++;
            System.out.println("lineNum = " + lineNum);
            String str1 = input1.line;
            String str2 = input2.line;
            ObjectMapper mapper1 = new ObjectMapper();
            ObjectMapper mapper2 = new ObjectMapper();
            JsonNode root1 = mapper1.readTree(str1);
            JsonNode root2 = mapper2.readTree(str2);
            JsonNode mediaNode1 = root1.path("query").path("results").path("mediaObj");
            JsonNode mediaNode2 = root2.path("query").path("results").path("mediaObj");
            if (mediaNode2.isMissingNode() && !mediaNode1.isMissingNode())
                tempCount += mediaNode1.size();
            //For yqlp
            if (mediaNode2.isArray()) {
                totalIDNum2 += mediaNode2.size();
                for (int i = 0; i < mediaNode2.size(); i++) {
                    ObjectNode mediaObj = (ObjectNode) mediaNode2.get(i);
                    mediaObj.put("yvap", "");
                    JsonNode streamsNode = mediaObj.path("streams");
                    //streams
                    if (streamsNode.isArray()) {
                        for (int j = 0; j < streamsNode.size(); j++) {
                            ObjectNode streamsObj = (ObjectNode) streamsNode.get(j);
                            changeStreamsPath(streamsObj);
                            ChangedHost(streamsObj);
                            //if(streamsObj.path("h264_profile").isMissingNode())
                            streamsObj.put("h264_profile", "");
                            if (streamsObj.path("is_primary").isMissingNode())
                                streamsObj.put("is_primary", false);
                        }
                    }
                    //meta
                    if (!mediaObj.path("meta").isMissingNode()) {
                        ObjectNode metaObj = (ObjectNode) mediaObj.path("meta");
                        changeMetaThumbnail(metaObj);
                        if (metaObj.path("show_name").isMissingNode())
                            metaObj.put("show_name", "");
                        if (metaObj.path("event_start").isMissingNode())
                            metaObj.put("event_start", "");
                        if (metaObj.path("event_stop").isMissingNode())
                            metaObj.put("event_stop", "");
                        //if(metaObj.path("credits").path("label").isMissingNode())
                        ((ObjectNode) metaObj.path("credits")).put("label", "");
                    }
                    //Metrics -> plidl & isrc
                    changeMetrics(mediaObj);
                }
            }

            //For yql
            if (mediaNode1.isArray()) {
                totalIDNum1 += mediaNode1.size();
                for (int i = 0; i < mediaNode1.size(); i++) {
                    JsonNode mediaObj = mediaNode1.get(i);
                    ((ObjectNode) mediaObj).put("yvap", "");
                    //Meta
                    //System.out.println("meta: ");
                    if (!mediaObj.path("meta").isMissingNode()) {
                        ObjectNode metaObj = (ObjectNode) mediaObj.path("meta");
                        changeMetaThumbnail(metaObj);
                        metaObj.put("event_start", "");
                        metaObj.put("event_stop", "");
                        FloatingtoInt(metaObj, "duration");
                        if (metaObj.path("show_name").isMissingNode())
                            metaObj.put("show_name", "");
                        //System.out.println("thub_dem: ");
                        if (!metaObj.path("thumbnail_dimensions").isMissingNode()) {
                            ObjectNode thub_demObj = (ObjectNode) metaObj.path("thumbnail_dimensions");
                            FloatingtoInt(thub_demObj, "height");
                            FloatingtoInt(thub_demObj, "width");
                        }
                        ((ObjectNode) metaObj.path("credits")).put("label", "");
                    }
                    //Visualseek
                    //System.out.println("visualseek: ");
                    if (!mediaObj.path("visualseek").isMissingNode()) {
                        ObjectNode visualseekObj = (ObjectNode) mediaObj.path("visualseek");
                        FloatingtoInt(visualseekObj, "frequency");
                        FloatingtoInt(visualseekObj, "width");
                        FloatingtoInt(visualseekObj, "height");
                        //visualseek -> images, float to int
                        JsonNode imagesNode = visualseekObj.path("images");
                        if (imagesNode.isArray()) {
                            for (int j = 0; j < imagesNode.size(); j++) {
                                ObjectNode imageObj = (ObjectNode) imagesNode.get(j);
                                FloatingtoInt(imageObj, "start_index");
                                FloatingtoInt(imageObj, "count");
                            }
                        }
                    }
                    //Streams
                    //System.out.println("streams: ");
                    JsonNode streamsNode = mediaObj.path("streams");
                    if (streamsNode.isArray()) {
                        for (int j = 0; j < streamsNode.size(); j++) {
                            ObjectNode streamsObj = (ObjectNode) streamsNode.get(j);
                            FloatingtoInt(streamsObj, "height");
                            FloatingtoInt(streamsObj, "bitrate");
                            FloatingtoInt(streamsObj, "duration");
                            FloatingtoInt(streamsObj, "width");
                            changeStreamsPath(streamsObj);
                            ChangedHost(streamsObj);
                            //                        if(streamsObj.path("h264_profile").isMissingNode())
                            streamsObj.put("h264_profile", "");
                            if (streamsObj.path("is_primary").isMissingNode())
                                streamsObj.put("is_primary", false);
                        }
                    }
                    //Metrics -> plidl & isrc
                    changeMetrics(mediaObj);
                }
            }

            //Compare
            if (mediaNode2.isArray() && mediaNode1.isArray()) {
                for (int i = 0; i < mediaNode2.size() && i < mediaNode1.size(); i++) {
                    JsonNode mediaObj1 = mediaNode1.get(i);
                    JsonNode mediaObj2 = mediaNode2.get(i);
                    if (!mediaObj1.equals(mediaObj2)) {
                        if (!mediaObj1.path("id").toString().equals(mediaObj2.path("id").toString())) {
                            errorCount++;
                        } else {
                            Integer IFdiffStreams = 0;
                            Integer IFdiffMeta = 0;
                            Integer IFdiffvisualseek = 0;
                            Integer IFdiffMetrics = 0;
                            Integer IFdifflicense = 0;
                            Integer IFdiffclosedcaptions = 0;
                            String statusCode = "";
                            MetaClass tempMeta = new MetaClass();
                            if (!mediaObj1.path("status").equals(mediaObj2.path("status"))) {
                                JsonNode statusNode1 = mediaObj1.path("status");
                                JsonNode statusNode2 = mediaObj2.path("status");
                                if (statusNode2.path("code").toString().equals("\"100\"")
                                        || (statusNode1.path("code").toString().equals("\"400\"")
                                                && statusNode1.path("code").toString().equals("\"404\""))
                                        || (statusNode1.path("code").toString().equals("\"200\"")
                                                && statusNode1.path("code").toString().equals("\"200\""))
                                        || (statusNode1.path("code").toString().equals("\"200\"")
                                                && statusNode1.path("code").toString().equals("\"403\"")))
                                    statusCode = "";
                                else
                                    statusCode = "yql code: " + mediaObj1.path("status").toString()
                                            + " yqlp code:" + mediaObj2.path("status").toString();
                            } else {//Status code is 100
                                if (!mediaObj1.path("streams").equals(mediaObj2.path("streams")))
                                    IFdiffStreams = 1;
                                if (!tempMeta.CompareMeta(mediaObj1.path("meta"), mediaObj2.path("meta"),
                                        lineNum))
                                    IFdiffMeta = 1;
                                if (!mediaObj1.path("visualseek").equals(mediaObj2.path("visualseek")))
                                    IFdiffvisualseek = 1;
                                if (!mediaObj1.path("metrics").equals(mediaObj2.path("metrics"))) {
                                    IFdiffMetrics = 1;
                                    JsonNode metrics1 = mediaObj1.path("metrics");
                                    JsonNode metrics2 = mediaObj2.path("metrics");
                                    if (!metrics1.path("beacons").equals(metrics2.path("beacons")))
                                        beacons++;
                                }
                                if (!mediaObj1.path("license").equals(mediaObj2.path("license")))
                                    IFdifflicense = 1;
                                if (!mediaObj1.path("closedcaptions").equals(mediaObj2.path("closedcaptions")))
                                    IFdiffclosedcaptions = 1;
                            }
                            if (IFdiffStreams + IFdiffMeta + IFdiffvisualseek + IFdiffMetrics + IFdifflicense
                                    + IFdiffclosedcaptions != 0 || !statusCode.equals("")) {
                                String ID_str = mediaObj1.path("id").toString();
                                if (!IDarray.containsKey(ID_str)) {
                                    IDclass temp_IDclass = new IDclass(ID_str);
                                    temp_IDclass.addNum(IFdiffStreams, IFdiffMeta, IFdiffvisualseek,
                                            IFdiffMetrics, IFdifflicense, IFdiffclosedcaptions, lineNum);
                                    if (!statusCode.equals(""))
                                        temp_IDclass.statusCode = statusCode;
                                    IDarray.put(ID_str, temp_IDclass);
                                } else {
                                    IDarray.get(ID_str).addNum(IFdiffStreams, IFdiffMeta, IFdiffvisualseek,
                                            IFdiffMetrics, IFdifflicense, IFdiffclosedcaptions, lineNum);
                                    if (!statusCode.equals(""))
                                        IDarray.get(ID_str).statusCode = statusCode;
                                }
                                IDarray.get(ID_str).stream.CompareStream(IFdiffStreams,
                                        mediaObj1.path("streams"), mediaObj2.path("streams"), lineNum);
                                if (!IDarray.get(ID_str).metaDone) {
                                    IDarray.get(ID_str).meta = tempMeta;
                                    IDarray.get(ID_str).metaDone = true;
                                }
                            } else
                                equalIDwithDuplicate++;
                        }
                    } else
                        equalIDwithDuplicate++;
                }
            }
            bw.flush();
            console.flush();

        } //while
        System.out.println("done");
        bw.write("Different ID" + "   " + "num   ");
        bw.write(PrintStreamsTitle());
        bw.write(PrintMetaTitle());
        bw.write(PrintTitle());
        bw.newLine();
        Iterator<String> iter = IDarray.keySet().iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            bw.write(key + "   ");
            bw.write(IDarray.get(key).num.toString() + "   ");
            bw.write(IDarray.get(key).stream.print());
            bw.write(IDarray.get(key).meta.print());
            bw.write(IDarray.get(key).print());
            bw.newLine();
            //System.out.println(key);
        }
        //System.out.println("different log num = " + diffNum);
        //System.out.println("same log num = " + sameLogNum);
        System.out.println("Different ID size = " + IDarray.size());
        //         System.out.println("streamEqual = " + streamEqual);
        //         System.out.println("metaEqual = " + metaEqual);
        //         System.out.println("metricsEqual = " + metricsEqual);
        //         System.out.println("visualseekEqual = " + visualseekEqual);
        //         System.out.println("licenseEqual = " + licenseEqual);
        //         System.out.println("closedcaptionsEqualEqual = " + closedcaptionsEqual);
        System.out.println(tempCount);
        System.out.println("beacons = " + beacons);
        System.out.println("equalIDwithDuplicate = " + equalIDwithDuplicate);
        System.out.println("Total ID num yql (including duplicates) = " + totalIDNum1);
        System.out.println("Total ID num yqpl (including duplicates) = " + totalIDNum2);
        System.out.println("Error " + errorCount);
        bw.close();
        console.close();
    } catch (IOException e) {
    }
}

From source file:com.ibm.watson.catalyst.corpus.tfidf.ApplyTemplate.java

public static void main(String[] args) {

    System.out.println("Loading Corpus.");
    JsonNode root;//ww  w  .j a  v  a 2  s  .  c  om
    TermCorpus c;
    JsonNode documents;
    try (InputStream in = new FileInputStream(new File("tfidf-health-1.json"))) {
        root = MAPPER.readTree(in);
        documents = root.get("documents");
        TermCorpusBuilder cb = new TermCorpusBuilder();
        cb.setDocumentCombiner(0, 0);
        cb.setJson(new File("health-corpus.json"));
        c = cb.build();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    } catch (JsonProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    }
    System.out.println("Corpus loaded.");

    List<TemplateMatch> matches = new ArrayList<TemplateMatch>();
    Iterator<TermDocument> documentIterator = c.getDocuments().iterator();

    int index = 0;
    for (JsonNode document : documents) {
        Pattern p1 = Template.getTemplatePattern(document, "\\b(an? |the )?(\\w+ ){0,4}",
                "( \\w+)?(?= is (an?|one|the)\\b)");
        if (p1.toString().equals("\\b(an? |the )?(\\w+ ){0,4}()( \\w+)?(?= is (an?|one|the)\\b)"))
            continue;
        Pattern p2 = Template.getTemplatePattern(document, "^(\\w+ ){0,2}",
                "( \\w+){0,1}?(?=( can| may)? causes?\\b)");
        Pattern p3 = Template.getTemplatePattern(document, "(?<=the use of )(\\w+ ){0,3}",
                "( \\w+| ){0,2}?(?=( (and|does|in|for|can|is|as|to|of)\\b|\\.))");
        Pattern p4 = Template.getTemplatePattern(document, "^(\\w+ ){0,3}",
                "( \\w+){0,1}(?=( can| may) leads? to\\b)");
        Pattern p5 = Template.getTemplatePattern(document, "(?<=\\bthe risk of )(\\w+ ){0,3}",
                "( (disease|stroke|attack|cancer))?\\b");
        Pattern p6 = Template.getTemplatePattern(document, "(\\w{3,} ){0,3}",
                "( (disease|stroke|attack|cancer))?(?= is caused by\\b)");
        Pattern p7 = Template.getTemplatePattern(document, "(?<= is caused by )(\\w+ ){0,10}", "");
        Pattern p8 = Template.getTemplatePattern(document, "\\b", "( \\w{4,})(?= can be used)");
        Pattern p9 = Template.getTemplatePattern(document, "(?<= can be used )(\\w+ ){0,10}", "\\b");
        TermDocument d = documentIterator.next();

        DocumentMatcher dm = new DocumentMatcher(d);
        matches.addAll(dm.getParagraphMatches(p1, "What is ", "?"));
        matches.addAll(dm.getParagraphMatches(p2, "What does ", " cause?"));
        matches.addAll(dm.getParagraphMatches(p3, "How is ", " used?"));
        matches.addAll(dm.getParagraphMatches(p4, "What can ", " lead to?"));
        matches.addAll(dm.getParagraphMatches(p5, "What impacts the risk of ", "?"));
        matches.addAll(dm.getParagraphMatches(p6, "What causes ", "?"));
        matches.addAll(dm.getParagraphMatches(p7, "What is caused by ", "?"));
        matches.addAll(dm.getParagraphMatches(p8, "How can ", " be used?"));
        matches.addAll(dm.getParagraphMatches(p9, "What can be used ", "?"));
        System.out.print("Progress: " + ((100 * ++index) / documents.size()) + "%\r");
    }
    System.out.println();

    List<TemplateMatch> condensedMatches = new ArrayList<TemplateMatch>();

    for (TemplateMatch match : matches) {
        for (TemplateMatch baseMatch : condensedMatches) {
            if (match.sameQuestion(baseMatch)) {
                baseMatch.addAnswers(match);
                break;
            }
        }
        condensedMatches.add(match);
    }

    try (BufferedWriter bw = new BufferedWriter(new FileWriter("health-questions.txt"))) {
        for (TemplateMatch match : condensedMatches) {
            bw.write(match.toString());
        }
        bw.write("\n");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    System.out.println("Done and generated: " + condensedMatches.size());

}

From source file:org.eel.kitchen.jsonschema.validator.ObjectValidatorTest.java

private static void checkNodeAndPaths(final Set<JsonNode> actual, final JsonNode expected) {
    assertEquals(actual.size(), expected.size());

    final Set<JsonNode> expectedSet = ImmutableSet.copyOf(expected);
    final Set<JsonNode> actualSet = Sets.newHashSet();

    Map<String, JsonNode> map;
    ObjectNode node;//from w  ww . java 2  s  .c  om

    for (final JsonNode element : actual) {
        node = JsonNodeFactory.instance.objectNode();
        map = JacksonUtils.nodeToMap(element);
        node.putAll(map);
        actualSet.add(node);
    }

    assertEqualsNoOrder(actualSet.toArray(), expectedSet.toArray());
}

From source file:enmasse.controller.flavor.FlavorParser.java

public static Map<String, Flavor> parse(JsonNode root) {
    Map<String, Flavor> flavorMap = new LinkedHashMap<>();
    for (int i = 0; i < root.size(); i++) {
        Flavor flavor = parseFlavor(root.get(i));
        flavorMap.put(flavor.name(), flavor);
    }//  w ww .  j  ava  2s.  co  m
    return flavorMap;
}

From source file:controllers.Maps.java

/**
 * Resolves the longitude and latitude for a given address ID
 *
 * @param addressId The address to resolve
 * @return A promise with the longitude and latitude
 *//*from  w  ww.j  av  a  2 s .c  o  m*/
@InjectContext
// TODO: inject context probably does not work here
public static Promise<F.Tuple<Double, Double>> getLatLongPromise(int addressId) {
    AddressDAO dao = DataAccess.getInjectedContext().getAddressDAO();
    Address address = dao.getAddress(addressId);
    if (address != null) {
        return WS.url(ADDRESS_RESOLVER)
                .setQueryParameter("street", address.getNum() + " " + address.getStreet())
                .setQueryParameter("city", address.getCity()).setQueryParameter("country", "Belgium")
                // TODO: uncomment postalcode line, it's only commented for test data purposes
                // .setQueryParameter("postalcode", address.getZip())
                .setQueryParameter("format", "json").get().map(response -> {
                    JsonNode node = response.asJson();
                    if (node.size() > 0) {
                        JsonNode first = node.get(0);
                        return new F.Tuple<>(first.get("lat").asDouble(), first.get("lon").asDouble());
                    } else
                        return null;
                });
    } else
        throw new DataAccessException("Could not find address by ID");
}

From source file:tests.SearchEntitiesNarrowByTypeTests.java

private static void search(final String q, final int hits) {
    running(TEST_SERVER, new Runnable() {
        @Override/*from  w w  w  .j a  v a  2  s  . c o  m*/
        public void run() {
            String response = call(q);
            assertThat(response).isNotNull();
            final JsonNode jsonObjectIds = Json.parse(response);
            assertThat(jsonObjectIds.isArray()).isTrue();
            assertThat(jsonObjectIds.size()).isEqualTo(hits + META);
        }
    });
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java

public static boolean hasLine(String line, Context context) {
    boolean ret = false;
    String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
    JsonNode actualObj = Util.stringToJsonNode(bufferString);
    JsonNode lines = actualObj.get("lines");
    for (int i = 0; i < lines.size(); i++) {
        JsonNode lineJson = lines.get(i);
        if (lineJson.get("name").asText().equalsIgnoreCase(line)) {
            ret = true;/*w ww  .  ja va  2  s  . co m*/
            break;
        }
    }
    return ret;
}

From source file:com.squarespace.template.plugins.platform.PlatformUtils.java

public static void makeSocialButton(JsonNode website, JsonNode item, boolean inline, StringBuilder buf) {
    JsonNode options = website.path("shareButtonOptions");
    if (website.isMissingNode() || options.isMissingNode() || options.size() == 0) {
        return;/*  ww  w  .  jav  a  2  s.c  o m*/
    }

    JsonNode node = GeneralUtils.getFirstMatchingNode(item, "systemDataId", "mainImageId");
    String imageId = node.asText();
    node = item.path("assetUrl");
    String assetUrl = node.asText();
    if (node.isMissingNode()) {
        node = item.path("mainImage").path("assetUrl");
        assetUrl = node.asText();
    }
    String style = (inline) ? "inline-style" : "button-style";
    if (inline) {
        buf.append("<span ");
    } else {
        buf.append("<div ");
    }
    buf.append("class=\"squarespace-social-buttons ");
    buf.append(style);
    buf.append("\" data-system-data-id=\"");
    buf.append(imageId);
    buf.append("\" data-asset-url=\"");
    buf.append(assetUrl);
    buf.append("\" data-record-type=\"");
    buf.append(item.path("recordType").asText());
    buf.append("\" data-full-url=\"");
    buf.append(item.path("fullUrl").asText());
    buf.append("\" data-title=\"");
    PluginUtils.escapeHtmlAttribute(item.path("title").asText(), buf);
    buf.append("\">");
    if (inline) {
        buf.append("</span>");
    } else {
        buf.append("</div>");
    }
}