Skip to content

Commit

Permalink
Really basic interfaces for natlib, more to come in the next selected…
Browse files Browse the repository at this point in the history
… push!
  • Loading branch information
NiteshOswal committed Apr 12, 2017
1 parent 9c9fdc5 commit 45cd9e1
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 9 deletions.
9 changes: 0 additions & 9 deletions Modules/MotivationBot/bot.py

This file was deleted.

Empty file added modules/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions modules/import.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "1.0.0",
"apps": {
"MotivationBot": "0.1.0",
"HelloBot": "0.1.0",
"TimeBot": "0.1.0"
}
}
14 changes: 14 additions & 0 deletions natlib/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Command(object):

def __init__(self):
super(Command, self).__init__()

def getInstance(self):
return self

def run(self):
pass

def intent(self):
pass

18 changes: 18 additions & 0 deletions natlib/intent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from command import Command

#
# The Abstract Intent
# Contains the default methods to define an intent
#
class Intent(object):

def __init__(self, command):
super(Intent, self).__init__()
if type(command) is Command:
self.command = command # command has to be final function that runs it.

def hook(self, hook, command):
pass

def runCommand(self):
return self.command()
31 changes: 31 additions & 0 deletions natlib/pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from intent import Intent
from collections import OrderedDict

# Basic Pipeline
# (TODO): Add basic LRU like features to find then most used intent in first few tests
class Pipeline(object):
def __init__(self):
self._pipeline = OrderedDict();
self.

def hook(self, key, intent):
if type(intent) is Intent:
self._pipeline[key] = {
"instance": intent,
"parsed": [] # for future, if we want to lookup which commands it parsed earlier..
}
else:
raise AttributeError("Invalid Intent")

def unhook(self, key):
intent = self._pipeline[key]
del self._pipeline[key]
return intent

def findIntent(self, input): # returns the the intents which test positive in the pipeline to be executed!
intents = []
for key, intent in self._pipeline:
if intent["instance"].test(input):
return intents


12 changes: 12 additions & 0 deletions natlib/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Response(object):
# Idea is we can send in message in a response,
# and the response can then be handled in different ways via this interface
def __init__(self, message):
self.message = message

# Hooks to the text to speech API to say things
def speak(self):
pass

def say(self):
print(self.message)

0 comments on commit 45cd9e1

Please sign in to comment.