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();
}
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();
}
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;
}
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;
}
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();
}
Aggregations