Package com.semedy.reasoner.core
Class JsonUtils
java.lang.Object
com.semedy.reasoner.core.JsonUtils
Methods for handling Jsons
- Author:
- angele
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a value to a Json arraystatic void
add a key value pair to a Json objectstatic org.json.JSONObject
arrayify
(org.json.JSONObject json, org.json.JSONObject schema) create arrays according to the arrays in the schemastatic org.json.JSONObject
arrayifySchema
(Object value) create arrays in a Json schema for enumsstatic 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.static org.json.JSONObject
createJsonObject
(Pattern pattern, TermParser parser) Create a json object from a pattern with values as a result of a mutation graphqlstatic 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 triplesstatic org.json.JSONObject
createJSONObject
(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 String
createLogEntry
(String action, String jsonToAdd, String jsonToDelete, String path, boolean addTimestamp) Creates a json object which will be written to the log file.static Pattern
createPattern
(org.json.JSONObject json) create a pattern out of a json objectstatic String
createQuery
(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.JSONObject
fillPattern
(Pattern pattern, ResultBuffer buffer, Map<String, Set<String>> subclasses) fill a graphql pattern with the result of a querystatic JsonIdentifier
getIdentifier
(JsonIdentifier topid, String name, int index, org.json.JSONObject json) static JsonIdentifier
static JsonIdentifier
getTopIdentifier
(org.json.JSONObject json) static boolean
isContainedIn
(String json, List<org.json.JSONObject> jsons, TermParser parser, String[] setProperties) Is json contained in jsonsstatic boolean
isContainedIn
(org.json.JSONObject jsonobj, String jsons, TermParser parser) Is json contained in jsonsstatic boolean
isContainedIn
(org.json.JSONObject jsonobj, String jsons, TermParser parser, String[] setProperties) Is json contained in jsonsstatic boolean
isEqual
(String json1, String json2, TermParser parser) Is json1 object equal to json2 objectstatic boolean
isEqual
(String json1, String json2, TermParser parser, String[] setProperties) Is json1 object equal to json2 objectstatic boolean
isEqual
(org.json.JSONObject json1, String json2, TermParser parser, String[] setProperties) static boolean
isEqual
(org.json.JSONObject json1, org.json.JSONObject json2, TermParser parser, String[] setProperties) static void
joinJsons
(org.json.JSONObject source, org.json.JSONObject target, ResultBuffer resultBuffer) join two json objects according to their uids @uidstatic void
static int
match
(org.json.JSONObject json, org.json.JSONObject partialJson) static org.json.JSONObject
matchNreplace
(org.json.JSONObject json, org.json.JSONObject partialJson) static List<org.json.JSONObject>
read a set of jsons from streamstatic void
removeUids
(org.json.JSONObject json) remove uid fields which have been added by GraphQL parserstatic Calendar
timeToCalendar
(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:
IOException
SimpleParseException
-
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:
IOException
SimpleParseException
-
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:
IOException
SimpleParseException
-
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.JSONException
IOException
SemReasonerException
-
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.JSONException
IOException
SemReasonerException
-
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:
InstantiationException
IllegalAccessException
org.json.JSONException
ReasoningException
InterruptedException
IOException
SemReasonerException
-
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:
InstantiationException
IllegalAccessException
org.json.JSONException
ReasoningException
InterruptedException
IOException
SemReasonerException
-
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:
SimpleParseException
IOException
-
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:
SimpleParseException
IOException
-
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:
SimpleParseException
IOException
-
isEqual
public static boolean isEqual(org.json.JSONObject json1, org.json.JSONObject json2, TermParser parser, String[] setProperties) throws SimpleParseException, IOException - Throws:
SimpleParseException
IOException
-
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:
IOException
SimpleParseException
-
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:
IOException
SimpleParseException
-
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:
IOException
SimpleParseException
-
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:
IOException
SimpleParseException
-
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:
IOException
SymboltableException
-
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:
IOException
SymboltableException
-
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
-