Package com.semedy.reasoner.core
Class JsonUtils
java.lang.Object
com.semedy.reasoner.core.JsonUtils
Methods for handling Jsons
- Author:
- angele
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd a value to a Json arraystatic voidadd a key value pair to a Json objectstatic org.json.JSONObjectarrayify(org.json.JSONObject json, org.json.JSONObject schema) create arrays according to the arrays in the schemastatic org.json.JSONObjectarrayifySchema(Object value) create arrays in a Json schema for enumsstatic org.json.JSONObjectcreateGraphQLSchema(org.json.JSONObject jsonSchema) create a graph ql schema out of a json schema, which in turn has been created out of an OO-logic class.static org.json.JSONObjectcreateJsonObject(Pattern pattern, TermParser parser) Create a json object from a pattern with values as a result of a mutation graphqlstatic org.json.JSONObjectcreateJSONObject(JsonIdentifier id, Map<JsonIdentifier, List<Object[]>> objects, Map<JsonIdentifier, org.json.JSONObject> alreadyCreated, boolean decode) create a json with id out of triplesstatic org.json.JSONObjectcreateJSONObject(String jsonString) Create a Json objects out of a stringstatic List<org.json.JSONObject>createJSONObjects(String jsonString) Create a set of Json objects out of a string (array of jsons)createLiterals(Collection<org.json.JSONObject> jsons, TermParser parser, String module, boolean encode, Set<String> setProperties) Creating literals out of a set of Json objectscreateLiterals(List<Object[]> triples, Object module) createLiterals(org.json.JSONObject json, TermParser parser, Object module, boolean encode, Set<String> setProperties) Creating literals out of a json objectcreateLiteralsEncoded(Collection<Object[]> triples) create a set of literals out of a set of encoded triplescreateLiteralsEncoded(Collection<Object[]> triples, Object module) create a set of literals out of a set of encoded triplesstatic StringcreateLogEntry(String action, String jsonToAdd, String jsonToDelete, String path, boolean addTimestamp) Creates a json object which will be written to the log file.static PatterncreatePattern(org.json.JSONObject json) create a pattern out of a json objectstatic StringcreateQuery(Pattern pattern, String type) create an OO-logic query out of a pattern and typecreateSchemaTriples(org.json.JSONObject json) create additional triples for OO-logic schemacreateTriples(Collection<org.json.JSONObject> jsons, TermParser parser, boolean encode, Set<String> setProperties) Creating triples out of a set of Json objectscreateTriples(org.json.JSONObject json, TermParser parser, boolean encode, Set<String> setProperties) Creating triples out of a json objectstatic org.json.JSONObjectfillPattern(Pattern pattern, ResultBuffer buffer, Map<String, Set<String>> subclasses) fill a graphql pattern with the result of a querystatic JsonIdentifiergetIdentifier(JsonIdentifier topid, String name, int index, org.json.JSONObject json) static JsonIdentifierstatic JsonIdentifiergetTopIdentifier(org.json.JSONObject json) static booleanisContainedIn(String json, List<org.json.JSONObject> jsons, TermParser parser, String[] setProperties) Is json contained in jsonsstatic booleanisContainedIn(org.json.JSONObject jsonobj, String jsons, TermParser parser) Is json contained in jsonsstatic booleanisContainedIn(org.json.JSONObject jsonobj, String jsons, TermParser parser, String[] setProperties) Is json contained in jsonsstatic booleanisEqual(String json1, String json2, TermParser parser) Is json1 object equal to json2 objectstatic booleanisEqual(String json1, String json2, TermParser parser, String[] setProperties) Is json1 object equal to json2 objectstatic booleanisEqual(org.json.JSONObject json1, String json2, TermParser parser, String[] setProperties) static booleanisEqual(org.json.JSONObject json1, org.json.JSONObject json2, TermParser parser, String[] setProperties) static voidjoinJsons(org.json.JSONObject source, org.json.JSONObject target, ResultBuffer resultBuffer) join two json objects according to their uids @uidstatic voidstatic intmatch(org.json.JSONObject json, org.json.JSONObject partialJson) static org.json.JSONObjectmatchNreplace(org.json.JSONObject json, org.json.JSONObject partialJson) static List<org.json.JSONObject>read a set of jsons from streamstatic voidremoveUids(org.json.JSONObject json) remove uid fields which have been added by GraphQL parserstatic CalendartimeToCalendar(String time)
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
isContainedIn
public static boolean isContainedIn(String json, List<org.json.JSONObject> jsons, TermParser parser, String[] setProperties) throws SimpleParseException, IOException Is json contained in jsons- Parameters:
json- , one json object as stringjsons- , several json objects as stringsetProperties- , the properties which are represented as sets- Returns:
- Throws:
IOExceptionSimpleParseException
-
isContainedIn
public static boolean isContainedIn(org.json.JSONObject jsonobj, String jsons, TermParser parser, String[] setProperties) throws SimpleParseException, IOException Is json contained in jsons- Parameters:
jsonobj- , one json objectjsons- , several json objects as stringparser- , the parser for termssetProperties- , the properties which are represented as sets- Returns:
- Throws:
IOExceptionSimpleParseException
-
isContainedIn
public static boolean isContainedIn(org.json.JSONObject jsonobj, String jsons, TermParser parser) throws SimpleParseException, IOException Is json contained in jsons- Parameters:
jsonobj- , one json objectjsons- , several json objects as stringparser- , the parser for terms- Returns:
- Throws:
IOExceptionSimpleParseException
-
fillPattern
public static org.json.JSONObject fillPattern(Pattern pattern, ResultBuffer buffer, Map<String, Set<String>> subclasses) throws org.json.JSONException, IOException, SemReasonerExceptionfill a graphql pattern with the result of a query- Parameters:
pattern- , the graphql pattern to be filledbuffer- , result tuple of query variables, variables for directivesvariables- , variables and their valuessubclasses- , all sub classes for a class- Returns:
- Throws:
org.json.JSONExceptionIOExceptionSemReasonerException
-
createPattern
create a pattern out of a json object- Parameters:
json-- Returns:
-
createJsonObject
public static org.json.JSONObject createJsonObject(Pattern pattern, TermParser parser) throws org.json.JSONException, IOException, SemReasonerException Create a json object from a pattern with values as a result of a mutation graphql- Parameters:
pattern-parser- , term parser for creating correct values- Returns:
- Throws:
org.json.JSONExceptionIOExceptionSemReasonerException
-
joinJsons
public static void joinJsons(org.json.JSONObject source, org.json.JSONObject target, ResultBuffer resultBuffer) join two json objects according to their uids @uid- Parameters:
source-target-resultBuffer-
-
removeUids
public static void removeUids(org.json.JSONObject json) remove uid fields which have been added by GraphQL parser- Parameters:
json-
-
createQuery
create an OO-logic query out of a pattern and type- Parameters:
pattern-type-- Returns:
-
arrayify
public static org.json.JSONObject arrayify(org.json.JSONObject json, org.json.JSONObject schema) throws org.json.JSONException, ReasoningException, InterruptedException, IOException, SemReasonerException create arrays according to the arrays in the schema- Parameters:
json-schema-- Returns:
- Throws:
InstantiationExceptionIllegalAccessExceptionorg.json.JSONExceptionReasoningExceptionInterruptedExceptionIOExceptionSemReasonerException
-
arrayifySchema
public static org.json.JSONObject arrayifySchema(Object value) throws InstantiationException, IllegalAccessException, org.json.JSONException, ReasoningException, InterruptedException, IOException, SemReasonerException create arrays in a Json schema for enums- Parameters:
value-- Returns:
- Throws:
InstantiationExceptionIllegalAccessExceptionorg.json.JSONExceptionReasoningExceptionInterruptedExceptionIOExceptionSemReasonerException
-
isEqual
public static boolean isEqual(String json1, String json2, TermParser parser) throws SimpleParseException, IOException Is json1 object equal to json2 object- Parameters:
createsets- TODOjson1- , json object as stringjson2- , json object as string- Returns:
- Throws:
SimpleParseExceptionIOException
-
isEqual
public static boolean isEqual(String json1, String json2, TermParser parser, String[] setProperties) throws SimpleParseException, IOException Is json1 object equal to json2 object- Parameters:
createsets- TODOjson1- , json object as stringjson2- , json object as stringsetProperties- , properties which are represented as sets- Returns:
- Throws:
SimpleParseExceptionIOException
-
match
public static int match(org.json.JSONObject json, org.json.JSONObject partialJson) -
matchNreplace
public static org.json.JSONObject matchNreplace(org.json.JSONObject json, org.json.JSONObject partialJson) -
isEqual
public static boolean isEqual(org.json.JSONObject json1, String json2, TermParser parser, String[] setProperties) throws SimpleParseException, IOException - Throws:
SimpleParseExceptionIOException
-
isEqual
public static boolean isEqual(org.json.JSONObject json1, org.json.JSONObject json2, TermParser parser, String[] setProperties) throws SimpleParseException, IOException - Throws:
SimpleParseExceptionIOException
-
createJSONObjects
Create a set of Json objects out of a string (array of jsons)- Parameters:
jsonString- , the string containing the jsons- Returns:
-
createJSONObject
Create a Json objects out of a string- Parameters:
jsonString- , the string containing the json- Returns:
-
createTriples
public static List<Object[]> createTriples(org.json.JSONObject json, TermParser parser, boolean encode, Set<String> setProperties) throws IOException, SimpleParseException Creating triples out of a json object- Parameters:
json- , the Json objectparser- , the term parserencode- , should strings be encodedsetProperties- , the properties which are represented as sets- Returns:
- Throws:
IOExceptionSimpleParseException
-
createSchemaTriples
create additional triples for OO-logic schema- Parameters:
json-- Returns:
-
createTriples
public static List<Object[]> createTriples(Collection<org.json.JSONObject> jsons, TermParser parser, boolean encode, Set<String> setProperties) throws IOException, SimpleParseException Creating triples out of a set of Json objects- Parameters:
jsons- , the Json objectsparser- , the term parserencode- , should strings be encodedsetProperties- , those properties which are represented as sets- Returns:
- Throws:
IOExceptionSimpleParseException
-
createGraphQLSchema
public static org.json.JSONObject createGraphQLSchema(org.json.JSONObject jsonSchema) create a graph ql schema out of a json schema, which in turn has been created out of an OO-logic class.
Only those schemas which can be created from OO-logic classes can be processed- Parameters:
jsonSchema- , the json schema- Returns:
-
createJSONObject
public static org.json.JSONObject createJSONObject(JsonIdentifier id, Map<JsonIdentifier, List<Object[]>> objects, Map<JsonIdentifier, org.json.JSONObject> alreadyCreated, boolean decode) create a json with id out of triples- Parameters:
id-objects-alreadyCreated-decode- , apply string decoding- Returns:
-
createLiterals
public static List<Literal> createLiterals(Collection<org.json.JSONObject> jsons, TermParser parser, String module, boolean encode, Set<String> setProperties) throws IOException, SimpleParseException Creating literals out of a set of Json objects- Parameters:
jsons- , the Json objectssetProperties- , the properties which are represented as sets- Returns:
- Throws:
IOExceptionSimpleParseException
-
createLiterals
public static List<Literal> createLiterals(org.json.JSONObject json, TermParser parser, Object module, boolean encode, Set<String> setProperties) throws IOException, SimpleParseException Creating literals out of a json object- Parameters:
json- , the Json objectsetProperties- , the properties which are represented as set- Returns:
- Throws:
IOExceptionSimpleParseException
-
getIdentifier
public static JsonIdentifier getIdentifier(JsonIdentifier topid, String name, int index, org.json.JSONObject json) -
getTopIdentifier
-
getTopIdentifier
-
createLiterals
-
createLiteralsEncoded
public static List<Literal> createLiteralsEncoded(Collection<Object[]> triples) throws SymboltableException, IOException create a set of literals out of a set of encoded triples- Parameters:
triples-- Returns:
- Throws:
IOExceptionSymboltableException
-
createLiteralsEncoded
public static List<Literal> createLiteralsEncoded(Collection<Object[]> triples, Object module) throws SymboltableException, IOException create a set of literals out of a set of encoded triples- Parameters:
triples-module-- Returns:
- Throws:
IOExceptionSymboltableException
-
timeToCalendar
-
addValue
add a key value pair to a Json object- Parameters:
obj- , json objectkey- , keyvalue- , value
-
addValue
Add a value to a Json array- Parameters:
obj-value-
-
createLogEntry
public static String createLogEntry(String action, String jsonToAdd, String jsonToDelete, String path, boolean addTimestamp) Creates a json object which will be written to the log file. The json object is made up of the action (create, update, delete) the json of the (created, updated, deleted) element and a timestamp.- Parameters:
action- (create, update, delete, load)json- of the element which is created, updated or deleted or path of file to be loadedaddTimestamp- current timestamp- Returns:
-
readJsonFromStream
read a set of jsons from stream- Parameters:
in-- Returns:
- Throws:
IOException
-
main
-