Search in sources :

Example 66 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project CoreNLP by stanfordnlp.

the class ConstantsAndVariables method getLearnedWordsAsJsonLastIteration.

public String getLearnedWordsAsJsonLastIteration() {
    JsonObjectBuilder obj = Json.createObjectBuilder();
    for (String label : getLabels()) {
        Counter<CandidatePhrase> learnedWords = getLearnedWordsEachIter(label).lastEntry().getValue();
        JsonArrayBuilder arr = Json.createArrayBuilder();
        for (CandidatePhrase k : learnedWords.keySet()) arr.add(k.getPhrase());
        obj.add(label, arr);
    }
    return obj.build().toString();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 67 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project CoreNLP by stanfordnlp.

the class NeuralCorefDataExporter method getSentenceArray.

private static JsonArray getSentenceArray(List<CoreLabel> sentence) {
    JsonArrayBuilder sentenceBuilder = Json.createArrayBuilder();
    sentence.stream().map(CoreLabel::word).map(w -> w.equals("/.") ? "." : w).map(w -> w.equals("/?") ? "?" : w).forEach(sentenceBuilder::add);
    return sentenceBuilder.build();
}
Also used : SentencesAnnotation(edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation) JsonArrayBuilder(javax.json.JsonArrayBuilder) HashMap(java.util.HashMap) Dictionaries(edu.stanford.nlp.coref.data.Dictionaries) ArrayList(java.util.ArrayList) CorefCluster(edu.stanford.nlp.coref.data.CorefCluster) Mention(edu.stanford.nlp.coref.data.Mention) Map(java.util.Map) Json(javax.json.Json) Pair(edu.stanford.nlp.util.Pair) CoreMap(edu.stanford.nlp.util.CoreMap) PrintWriter(java.io.PrintWriter) JsonObject(javax.json.JsonObject) Dataset(edu.stanford.nlp.coref.CorefProperties.Dataset) CoreLabel(edu.stanford.nlp.ling.CoreLabel) Properties(java.util.Properties) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) SemanticGraphEdge(edu.stanford.nlp.semgraph.SemanticGraphEdge) Iterator(java.util.Iterator) IOUtils(edu.stanford.nlp.io.IOUtils) JsonArray(javax.json.JsonArray) DocType(edu.stanford.nlp.coref.data.Document.DocType) File(java.io.File) List(java.util.List) StringUtils(edu.stanford.nlp.util.StringUtils) CorefDocumentProcessor(edu.stanford.nlp.coref.CorefDocumentProcessor) CorefProperties(edu.stanford.nlp.coref.CorefProperties) Document(edu.stanford.nlp.coref.data.Document) CorefUtils(edu.stanford.nlp.coref.CorefUtils) JsonObjectBuilder(javax.json.JsonObjectBuilder) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 68 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project mysql_perf_analyzer by yahoo.

the class SNMPSettings method writeToJson.

private boolean writeToJson(Writer writer) {
    javax.json.JsonWriter wr = null;
    try {
        JsonObjectBuilder settingBuilder = Json.createObjectBuilder();
        settingBuilder.add("site", toJson(this.siteSetting));
        JsonArrayBuilder groupBuilder = Json.createArrayBuilder();
        for (Map.Entry<String, SNMPSetting> e : this.groupSettings.entrySet()) {
            JsonObjectBuilder grp = toJson(e.getValue());
            grp.add("dbgroup", e.getKey());
            groupBuilder.add(grp);
        }
        settingBuilder.add("group", groupBuilder);
        JsonArrayBuilder hostBuilder = Json.createArrayBuilder();
        for (Map.Entry<String, SNMPSetting> e : this.hostSettings.entrySet()) {
            JsonObjectBuilder host = toJson(e.getValue());
            host.add("dbhost", e.getKey());
            hostBuilder.add(host);
        }
        settingBuilder.add("host", hostBuilder);
        wr = javax.json.Json.createWriter(writer);
        JsonObject jsonObj = settingBuilder.build();
        wr.writeObject(jsonObj);
        wr.close();
        wr = null;
        return true;
    } catch (Exception ex) {
        logger.log(Level.INFO, "Failed to store snmp json", ex);
    } finally {
        if (wr != null)
            try {
                wr.close();
            } catch (Exception ex) {
            }
    }
    return false;
}
Also used : JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 69 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project visualee by Thomas-S-B.

the class GraphCreator method buildJSONNodes.

static JsonArrayBuilder buildJSONNodes(DependencyFilter filter) {
    Set<JavaSource> relevantClasses = DependencyContainer.getInstance().getFilteredJavaSources(filter);
    JsonArrayBuilder nodesArray = Json.createArrayBuilder();
    for (JavaSource javaSource : JavaSourceContainer.getInstance().getJavaSources()) {
        if (filter == null || relevantClasses.contains(javaSource)) {
            nodesArray.add(buildJSONNode(javaSource));
        }
    }
    return nodesArray;
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 70 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentUtils method getEditorJSON.

/**
 * Returns a JSON representation of given content fragment taking optional element names and a variation name into
 * account.
 *
 * @param contentFragment The content fragment
 * @param variationName   An optional variation name
 * @param elementNames    Optional element names
 * @return A JSON representation of the content fragment
 */
public static String getEditorJSON(final ContentFragment contentFragment, final String variationName, final String[] elementNames) {
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    jsonObjectBuilder.add("title", contentFragment.getTitle());
    Resource contentFragmentResource = contentFragment.adaptTo(Resource.class);
    if (contentFragmentResource != null) {
        jsonObjectBuilder.add("path", contentFragmentResource.getPath());
    }
    if (variationName != null) {
        jsonObjectBuilder.add("variation", variationName);
    }
    if (elementNames != null) {
        JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
        for (String elementName : elementNames) {
            arrayBuilder.add(elementName);
        }
        jsonObjectBuilder.add("elements", arrayBuilder);
    }
    Iterator<Resource> associatedContentIterator = contentFragment.getAssociatedContent();
    if (associatedContentIterator.hasNext()) {
        JsonArrayBuilder associatedContentArray = Json.createArrayBuilder();
        while (associatedContentIterator.hasNext()) {
            Resource resource = associatedContentIterator.next();
            ValueMap valueMap = resource.adaptTo(ValueMap.class);
            JsonObjectBuilder contentObject = Json.createObjectBuilder();
            if (valueMap != null && valueMap.containsKey(JCR_TITLE)) {
                contentObject.add("title", valueMap.get(JCR_TITLE, String.class));
            }
            contentObject.add("path", resource.getPath());
            associatedContentArray.add(contentObject);
        }
        jsonObjectBuilder.add("associatedContent", associatedContentArray);
    }
    return jsonObjectBuilder.build().toString();
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

JsonArrayBuilder (javax.json.JsonArrayBuilder)177 JsonObjectBuilder (javax.json.JsonObjectBuilder)103 JsonObject (javax.json.JsonObject)36 Map (java.util.Map)29 Path (javax.ws.rs.Path)26 GET (javax.ws.rs.GET)24 HashMap (java.util.HashMap)19 JsonArray (javax.json.JsonArray)18 ArrayList (java.util.ArrayList)15 List (java.util.List)15 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)12 IOException (java.io.IOException)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)10 Dataset (edu.harvard.iq.dataverse.Dataset)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 JsonValue (javax.json.JsonValue)9 StringWriter (java.io.StringWriter)8 JsonString (javax.json.JsonString)7 Date (java.util.Date)6 JsonException (javax.json.JsonException)6