-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed handle_single_interlocutor_input (#130).
- Loading branch information
1 parent
b2bb42f
commit 43f8938
Showing
7 changed files
with
71 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,39 @@ | ||
import ravestate as rs | ||
import ravestate_rawio as rawio | ||
import ravestate_verbaliser as verbaliser | ||
import ravestate_phrases_basic_en as lang | ||
import ravestate_nlp as nlp | ||
import ravestate_ontology as mem | ||
|
||
from scientio.ontology.node import Node | ||
from scientio.session import Session | ||
from scientio.ontology.ontology import Ontology | ||
|
||
from reggol import get_logger | ||
logger = get_logger(__name__) | ||
|
||
ANON_INTERLOC_ID = "anonymous_interlocutor" | ||
ANON_INTERLOC_PATH = f"interloc:all:{ANON_INTERLOC_ID}" | ||
|
||
with rs.Module(name="interloc", depends=(rawio.mod, verbaliser.mod, mem.mod)) as mod: | ||
|
||
with rs.Module(name="interloc", depends=(nlp.mod, mem.mod)) as mod: | ||
|
||
# TODO: Make interloc:all a special property type, that only accepts ScientioNodeProperty as children | ||
prop_all = rs.Property(name="all", allow_read=True, allow_write=False, allow_push=True, allow_pop=True) | ||
prop_persisted = rs.Property(name="persisted", allow_read=True, allow_write=True, allow_push=True, allow_pop=True, | ||
always_signal_changed=True) | ||
|
||
|
||
def handle_single_interlocutor_input(ctx: rs.ContextWrapper, input_value: str, id=ANON_INTERLOC_ID) -> None: | ||
""" | ||
Forwards input to `rawio:in` and manages creation/deletion of a singleton | ||
interlocutor. A new interlocutor node is pushed, when the input is a greeting, | ||
and there is no interlocutor present. The interlocutor is popped, | ||
if the input is a farewell, and there is an interlocutor present. | ||
* `ctx`: Context Wrapper of the calling state. Must have read permissions | ||
for `interloc:all`. | ||
* `input_value`: The string input value that should be written to `rawio:in`. | ||
* `id`: Name of the interlocutor context property, and initial name for | ||
the interlocutor's Neo4j node (until a proper name is set by persqa). | ||
""" | ||
|
||
@rs.receptor(ctx_wrap=ctx, write=rawio.prop_in) | ||
def write_input(ctx_input, value: str): | ||
ctx_input[rawio.prop_in] = value | ||
|
||
@rs.receptor(ctx_wrap=ctx, write=prop_all) | ||
def push_interloc(ctx: rs.ContextWrapper, interlocutor_node: Node): | ||
if ctx.push( | ||
parent_property_or_path=prop_all, | ||
child=rs.Property(name=id, default_value=interlocutor_node)): | ||
logger.debug(f"Pushed {interlocutor_node} to interloc:all") | ||
|
||
@rs.receptor(ctx_wrap=ctx, write=prop_all) | ||
def pop_interloc(ctx: rs.ContextWrapper): | ||
if ctx.pop(f"interloc:all:{id}"): | ||
logger.debug(f"Popped interloc:all:{id}") | ||
|
||
write_input(input_value) | ||
|
||
interloc_exists = f"interloc:all:{id}" in ctx.enum(prop_all) | ||
|
||
# push Node if you got a greeting | ||
if input_value.strip() in verbaliser.get_phrase_list(lang.intent_greeting) and not interloc_exists: | ||
# set up scientio | ||
mem.initialized.wait() | ||
onto: Ontology = mem.get_ontology() | ||
|
||
# create scientio Node of type Person | ||
new_interloc = Node(metatype=onto.get_type("Person")) | ||
new_interloc.set_name(id) | ||
push_interloc(new_interloc) | ||
|
||
# pop Node if you got a farewell | ||
elif input_value.strip() in verbaliser.get_phrase_list("farewells") and interloc_exists: | ||
pop_interloc() | ||
@rs.state(cond=nlp.sig_intent_hi, write=prop_all) | ||
def push_interlocutor(ctx): | ||
interloc_exists = ANON_INTERLOC_PATH in ctx.enum(prop_all) | ||
if not interloc_exists: | ||
mem.initialized.wait() | ||
onto: Ontology = mem.get_ontology() | ||
new_interloc = Node(metatype=onto.get_type("Person")) | ||
new_interloc.set_name(ANON_INTERLOC_ID) | ||
if ctx.push( | ||
parent_property_or_path=prop_all, | ||
child=rs.Property(name=ANON_INTERLOC_ID, default_value=new_interloc)): | ||
logger.debug(f"Pushed {new_interloc} to interloc:all") | ||
|
||
@rs.state(cond=nlp.sig_intent_bye, write=prop_all) | ||
def pop_interlocutor(ctx): | ||
interloc_exists = ANON_INTERLOC_PATH in ctx.enum(prop_all) | ||
if interloc_exists and ctx.pop(ANON_INTERLOC_PATH): | ||
logger.debug(f"Popped {ANON_INTERLOC_PATH}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters