
prerna.sablecc2.om.NounStore Maven / Gradle / Ivy
The newest version!
package prerna.sablecc2.om;
import java.io.IOException;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.Constants;
import prerna.util.gson.GsonUtility;
public class NounStore implements Serializable{
private static final Logger classLogger = LogManager.getLogger(NounStore.class);
// each noun is typically a gen row struct
// I need to keep track of a couple of things
// a. Need to keep track of how many times a particular noun came through
// b. Keep the general array for what was the array for a given time
// c. Keep another general array which is a sum total of everything so far
String operationName = null;
public Hashtable nounCount = new Hashtable();
// S_1 would be the first time we saw S, S_2 would be the second time, S_3 would be.. well you know it
public Hashtable nounByNumber = new Hashtable();
public LinkedHashMap nounRow = new LinkedHashMap();
public final static String selector = "s";
public final static String projector = "p";
public final static String filter = "f";
public final static String all = "all";
public final static String joins = "j";
public NounStore(String operationName)
{
this.operationName = operationName;
}
// adds the noun
public void addNoun(String nounName, GenRowStruct struct)
{
// initialize to the current struct
GenRowStruct curStruct = struct;
// see if the noun exists first
// make the curstruct to be the actual struct
if(nounRow.containsKey(nounName))
{
curStruct = nounRow.get(nounName);
// I am creating a new one here
curStruct.merge(struct);
}
nounRow.put(nounName, curStruct);
// see if the count exists
int count = 0;
if(nounCount.containsKey(nounName))
count = nounCount.get(nounName);
count++;
nounCount.put(nounName, count);
// add this to the noun by number
nounByNumber.put(nounName+"_"+count, struct);
}
public int size()
{
return nounRow.size();
}
// get the total number of nouns
public int getCountForNoun(String nounName)
{
return nounCount.get(nounName);
}
// get the number of nouns
public int getNounNum()
{
return nounRow.size();
}
public Set getNounKeys() {
return nounRow.keySet();
}
// gets all the nouns for a particular noun name
public GenRowStruct getNoun(String nounName)
{
return nounRow.get(nounName);
}
// gets the noun at a particular number
public GenRowStruct getNoun(String nounName, int number)
{
return nounByNumber.get(nounName + "_" + number);
}
public GenRowStruct removeNoun(String nounName) {
return nounRow.remove(nounName);
}
/* // make a child nounstore
// pattern is the node that is coming in
public NounStore makeChildStore(String operation)
{
NounStore retStore = this;
if(!this.operationName.equals(operation))
{
retStore = new NounStore(operation);
childStore.put(operation, retStore);
}
// else there is a very good possibility they are just doing this for beautification
return retStore;
}
*/
// find if this is possible through query in this frame
public boolean isSQL()
{
// this should call each of the is SQL in the gen row struct
// and give back the result
return true;
}
public GenRowStruct makeNoun(String noun)
{
GenRowStruct newRow = new GenRowStruct();
// for now.. I will not keep the caridnality
if(nounRow.containsKey(noun))
newRow = nounRow.get(noun);
else
{
addNoun(noun, newRow);
}
return newRow;
}
public String getDataString() {
String s = "";
if(this.nounRow == null) return s;
for(String key : this.nounRow.keySet()) {
s += "KEY: "+key;
s += "\n";
s += "GENROWSTRUCT: "+nounRow.get(key);
s += "\n";
}
return s;
}
// need someway to get the actual store / data
public Hashtable getDataHash()
{
Hashtable retHash = new Hashtable();
// see if there are keys
// if there
Set keys = nounRow.keySet();
for(String thisKey : keys) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy