All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rosaenlg.lib.CompileOptions Maven / Gradle / Ivy

Go to download

Java wrapper around RosaeNLG (JavaScript Natural Language Generation library), using GraalVM

There is a newer version: 3.2.2
Show newest version
package org.rosaenlg.lib;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;

/*-
 * #%L
 * RosaeNLG for Java
 * %%
 * Copyright (C) 2019 RosaeNLG.org, Ludan Stoecklé
 * %%
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * #L%
 */

import org.json.JSONObject;

//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

/**
 * RosaeNLG compilation options helper.
 * 

* Compile options *

* @author Ludan Stoecklé [email protected] */ public class CompileOptions implements Cloneable { // private static final Logger logger = LoggerFactory.getLogger(CompileOptions.class); private String language; private String name; private Boolean compileDebug; private Boolean embedResources; private List verbs; private List adjectives; private List words; public Object clone() throws CloneNotSupportedException { return super.clone(); } /** Default constructor, does nothing. */ public CompileOptions() { } /** Constructor from json parsed object. * *

* Will find different properties in the json object and populate the object. *

* * @param compileOptionsJson json object containing the properties */ public CompileOptions(JSONObject compileOptionsJson) { if (compileOptionsJson.has("language")) { this.language = compileOptionsJson.getString("language"); } if (compileOptionsJson.has("name")) { this.name = compileOptionsJson.getString("name"); } if (compileOptionsJson.has("compileDebug")) { this.compileDebug = compileOptionsJson.getBoolean("compileDebug"); } if (compileOptionsJson.has("embedResources")) { this.embedResources = compileOptionsJson.getBoolean("embedResources"); } if (compileOptionsJson.has("verbs")) { this.verbs = jsonArrayToStringArray(compileOptionsJson.getJSONArray("verbs")); } if (compileOptionsJson.has("adjectives")) { this.adjectives = jsonArrayToStringArray(compileOptionsJson.getJSONArray("adjectives")); } if (compileOptionsJson.has("words")) { this.words = jsonArrayToStringArray(compileOptionsJson.getJSONArray("words")); } } private List jsonArrayToStringArray(JSONArray arr) { List res = new ArrayList(); for (int i = 0; i < arr.length(); i++) { res.add(arr.getString(i)); } return res; } /** * Serializes the object to a JSON String. * * @return String the object as a JSON String */ public String toJson() { JSONObject res = new JSONObject(); if (this.language != null) { res.put("language", this.language); } if (this.name != null) { res.put("name", this.name); } if (this.compileDebug != null) { res.put("compileDebug", this.compileDebug); } if (this.embedResources != null) { res.put("embedResources", this.embedResources); } if (this.verbs != null) { res.put("verbs", new JSONArray(this.verbs)); } if (this.adjectives != null) { res.put("adjectives", new JSONArray(this.adjectives)); } if (this.words != null) { res.put("words", new JSONArray(this.words)); } return res.toString(); } /** * Sets the language, for instance 'en_US' or 'fr_FR'. * * @param language the language * @return this to set further options */ public CompileOptions setLanguage(String language) { this.language = language; return this; } /** * Sets the name of the output function. *

* This is only useful for 'compileFileClient', 'compileClient' and 'compile' * methods. *

* * @param name name of the output function * @return this to set further options */ public CompileOptions setName(String name) { this.name = name; return this; } /** * Activates compile debug Pug option. *

* Is true by default in Pug. *

* * @param compileDebug activates or not compileDebug * @return this to set further options */ public CompileOptions setCompileDebug(Boolean compileDebug) { this.compileDebug = compileDebug; return this; } /** * Embed resources in the compiled function. *

* Useful for client-side rendering only. *

* * @param embedResources true to embed resources * @return this to set further options */ public CompileOptions setEmbedResources(Boolean embedResources) { this.embedResources = embedResources; return this; } /** * Set words to embed. *

* Useful for client-side rendering only. *

* * @param words list of words to embed * @return this to set further options */ public CompileOptions setWords(List words) { this.words = words; return this; } /** * Set verbs to embed. *

* Useful for client-side rendering only. *

* * @param verbs list of verbs to embed * @return this to set further options */ public CompileOptions setVerbs(List verbs) { this.verbs = verbs; return this; } /** * Set adjectives to embed. *

* Useful for client-side rendering only. *

* * @param adjectives list of adjectives to embed * @return this to set further options */ public CompileOptions setAdjectives(List adjectives) { this.adjectives = adjectives; return this; } /** * Returns the language. * * @return language */ public String getLanguage() { return this.language; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy