# State
1. Step : write 10 diffirent kind of questions in plain english
2. Write corresponding State Object
3. Finalize on Generic State Object
S, A --> S1 --> Stop Answer
what is the length of Ganga?
What is the population of India?
length - attribute
entity_type = river
entity_instance.name = Ganaga
message State {
repeated string domain = 1;
repeated string entity_type = 2; // river, country
map<string, StrSet> entity_instance = 2; // river, 1
repeated exclude
}
message EntityInstance {
}
Graph
* constraints (s,o,p)
* varibale node ?
* type of node, domain, entity_type, .......
message State{
repeated string objects = 1; // "objects" can be domain, entity, name, attribute, bizID or predicate
}
Q >> NLP >> Graph Question
```protobuf
message Question{
State state = 1;
repeated Action action = 2;
}
// State contians a list of "objects"
message State{
repeated string objects = 1; // "objects" can be domain entityType, entity, name, attribute, bizID or predicate
}
// Actions can add or remove "objects" from the state
message Action {
oneof ActionType{ // making each action atomic incase each type of action needs to perform diffently
DomainAction domain_action = 1;
EntityTypeAction entity_type_action = 2;
EntityAction entity_action = 3;
NameAction name_action = 4;
AttributeAction attribute_action = 5;
BizIDAction bizID_action = 6;
PredicateAction predicate_action = 7;
SpecialAction special_action = 8;
}
string order = 7;
}
// An action will be a triplet containing [head, action, tail]
// adds or remove domain to state
message DomainAction {
string head = 1;
string tail = 2;
ActionType action_type = 3;
}
// adds or remove entity to state
message EntityTypeAction {
string head = 1;
string tail = 2;
ActionType action_type = 3;
}
// adds or remove entity to state
message EntityAction {
string head = 1;
string tail = 2;
Action action = 3;
}
// adds or remove name to state
message NameAction {
string head = 1;
string tail = 2;
ActionType action_type = 3;
}
// adds or remove attribute to state
message AttributeAction {
string head = 1;
string tail = 2;
ActionType action_type = 3;
}
// adds or remove bizID to state
message BizIDAction {
string head = 1;
string tail = 2;
ActionType action_type = 3;
}
// adds or remove predicate to state
message PredicateAction {
string head = 1;
string tail = 2;
ActionType action_type = 3;
}
// defines what type of action needs to be taken
enum ActionType{
ADD = 1; // adds "objects" to state
REMOVE = 2; // remove "objects" to state
FETCH = 3; // fetches given element of "object"
}
// Action performing multiple actions
message SpecialAction{
oneof Action{
Sort sort = 1;
Filter filter = 2;
Limit limit = 3;
Loop loop = 4;
}
}
message Sort{
string parameter = 1;
bool is_asc = 2;
}
message Limit{
int32 lower_limit = 1;
int32 upper_limit = 2;
}
message Loop{
repeated Action action = 1;
uint32 loop_count = 2;
}
message Filter {
oneof filter_is_one_of {
BaseFilter base_filter = 1;
CompoundFilter compound_and_filter = 2;
CompoundFilter compound_or_filter = 3;
}
}
message BaseFilter {
oneof filter_is_one_of {
RangeFilter range_filter = 1;
ComparatorFilter comparator_filter = 2;
}
}
message CompoundFilter {
repeated Filter filter = 1;
}
message RangeFilter {
jio.brain.proto.base.BrainToken attribute_token = 1;
double lower = 2;
double upper = 3;
bool is_lower_equal = 4; // false ( and true [
bool is_upper_equal = 5; // false ) and true ]
}
message ComparatorFilter {
Comparator comparator = 1;
FilterValue lhs = 2;
FilterValue rhs = 3;
}
enum Comparator {
COMPARATOR_LT = 0; // <
COMPARATOR_LE = 1; // <=
COMPARATOR_GT = 2; // >
COMPARATOR_GE = 3; // >=
COMPARATOR_EQ = 4; // ==
COMPARATOR_NE = 5; // !=
}
message FilterValue {
oneof filter_value_is_one_of {
jio.brain.proto.base.BrainToken attribute_token = 1;
quantity.BrainQuantity attribute_quantity = 2;
}
}
```
#### Q1: What is the length of Ganga?
Initial State: x = []
> Actions are defined as (ActionType[head, action, tail], order)
**Initial Actions:** (EntityAction[Ganga, ADD, x], 1), (AttributeAction[length, FETCH, x], 2)
**Action 1:** Adds entity Ganga to the state
After performing action 1:
x = [Ganga]
Actions: (AttributeAction[length, FETCH, x], 2),
**Action 2:** Fetches length attribute of all the entities in the state; adds the attribute found; removes the entity
After performing action 2:
x = [Ganga - 2,510 km]
Actions:
Since no other action is left, we have reached our answer
#### Q2: What is the longest river in the world?
Initial State: x = []
**Initial Actions:** (EntityTypeAction[River, ADD, x], 1), (AttributeAction[length, FETCH, x], 2), (SpecialAction[Sort(length, ASC)], 3), (SpecialAction[LIMIT, 1], 4)
> Ideally actions should be following: (EntityTypeAction[River[0], ADD, x], 1), (AttributeAction[length, FETCH, x], 2), (SpecialAction[loop(EntityTypeAction[River[i], ADD, y], 1), (AttributeAction[length, FETCH, y], 2), SpecialAction[Filter(Cond(y,GR,x), CondTrue((AttributeAction[length, ADD, y], 1), (AttributeAction[length, REMOVE, x], 2)), CondFalse())])
**Action 1:** Adds all entities in 'River' entityType to the state
After performing action 1:
x = [Ganga, Yamuna, Amazon, Nile, ....]
Actions: (AttributeAction[length, FETCH, x], 2), (SpecialAction[Sort(length, ASC)], 3), (SpecialAction[LIMIT, 1], 4)
**Action 2:** Fetches the lengths of all the entities in state
After performing Action 2:
x = [Ganga - 2,510 km, Yamuna - 1,376 km, Amazon - 6,400 km , Nile - 6,650 km, ....]
Actions: (SpecialAction[Sort(length, ASC)], 3), (SpecialAction[LIMIT, 1], 4)
**Action 3:** Sort all the entities in state by length in ascending order
After performing Action 3:
x = [Nile - 6,650 km, Amazon - 6,400 km, ....]
Actions: (SpecialAction[LIMIT, 1], 4)
**Action 4:** Limits the answer to 1 entity
x = [Nile - 6,650 km]
Actions:
Since no other action is left, we have reached our answer.
#### Q3: What are the films directed by PK's director excuding Sanju?
Initial State: x = []
**Initial Actions:** (EntityAction(PK, ADD, y), 1), (PredicateAction(directed_by, FETCH, y), 2), ((EntityAction(y, ADD, x), 3), (PredicateAction(director, FETCH, x), 4), (EntityAction(Sanju, REMOVE, x), 5)
**Action 1:** Adds entity PK to state
y = [PK], x = []
Actions: (PredicateAction(directed_by, FETCH, y), 2), ((EntityAction(y, ADD, x), 3), (PredicateAction(director, FETCH, x), 4), (EntityAction(Sanju, REMOVE, x), 5)
**Action 2:** Traverses the KG and adds entities agreeing with the predicates.
y = [Rajkumar Hirani], x = []
Actions: ((EntityAction(y, ADD, x), 3), (PredicateAction(director, FETCH, x), 4), (EntityAction(Sanju, REMOVE, x), 5)
**Action 3:** Adds entity from y to x
x = [Rajkumar Hirani]
Actions: (PredicateAction(director, FETCH, x), 4), (EntityAction(Sanju, REMOVE, x), 5)
**Action 4:** Traverses the KG and gets entities agreeing with the predicate into the state
x = [Mission Kashmir, Munna Bhai M.B.B.S., Lage Raho Munna Bhai, 3 Idiots, Ferrari Ki Sawaari, PK, Saala Khadoos, Sanju]
Actions: (EntityAction(Sanju, REMOVE, x), 5)
**Action 5:** Removes entity 'Sanju' from the state.
x = [Mission Kashmir, Munna Bhai M.B.B.S., Lage Raho Munna Bhai, 3 Idiots, Ferrari Ki Sawaari, PK, Saala Khadoos]
Actions:
Since no other action is left, we have reached our answer.