Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
selBaez committed Jun 30, 2020
1 parent e40435d commit 233d39d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 75 deletions.
2 changes: 1 addition & 1 deletion apps/responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


class ResponderApp(AbstractApplication, StatisticsComponent,
SubtitlesComponent, # TODO: (un)comment to turn tablet subtitles On/Off
# SubtitlesComponent, # TODO: (un)comment to turn tablet subtitles On/Off
# DisplayComponent, SceneComponent, # TODO: (un)comment to turn Web View On/Off
# WikipediaResponder, # WolframResponder, # TODO: (un)comment to turn factual responder On/Off
ExploreComponent, # TODO: (un)comment to turn exploration On/Off
Expand Down
3 changes: 1 addition & 2 deletions ontologies/integration.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,7 @@ grasp:TemporalValue rdf:type owl:Class ;

### http://groundedannotationframework.org/grasp#Utterance
grasp:Utterance rdf:type owl:Class ;
rdfs:subClassOf gaf:Mention ,
sem:Event .
rdfs:subClassOf sem:Event .


### http://groundedannotationframework.org/grasp#Visual
Expand Down
46 changes: 27 additions & 19 deletions pepper/brain/LTM_statement_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def _link_entity(self, entity, graph, namespace_mapping=None):
graph.add((entity.id, RDF.type, entity_type))


def _link_detections(self, context, dect, prdt):
# Bidirectional link to context
self.interaction_graph.add((context.id, self.namespaces['EPS']['hasDetection'], dect.id))
self.instance_graph.add((dect.id, self.namespaces['EPS']['hasContext'], context.id))
# Create detection
detection = create_claim_graph(self, self.myself, prdt, dect, UtteranceType.EXPERIENCE)
self.claim_graph.add((detection.id, self.namespaces['EPS']['hasContext'], context.id))

return detection


def _create_detections(self, cntxt, context):
"""
Expand All @@ -55,23 +66,21 @@ def _create_detections(self, cntxt, context):

for item in cntxt.objects:
if item.name.lower() != 'person':
# Create instance and link detection to graph
# Create instance
mem_id, memory = get_object_id(memory, item.name)
objct_id = self._rdf_builder.fill_literal(mem_id, datatype=self.namespaces['XML']['string'])
objct = self._rdf_builder.fill_entity(casefold_text('%s %s' % (item.name, objct_id), format='triple'),
[casefold_text(item.name, format='triple'), 'Instance',
'object'],
[casefold_text(item.name, format='triple'), 'Instance', 'object'],
'LW')

# Link detection to graph
_link_entity(self, objct, self.instance_graph)
self.interaction_graph.add((objct.id, self.namespaces['N2MU']['id'], objct_id))
instances.append(objct)
# Bidirectional link to context
self.interaction_graph.add((context.id, self.namespaces['EPS']['hasDetection'], objct.id))
self.instance_graph.add((objct.id, self.namespaces['EPS']['hasContext'], context.id))
# Create detection
objct_detection = create_claim_graph(self, self.myself, prdt, objct, UtteranceType.EXPERIENCE)
self.claim_graph.add((objct_detection.id, self.namespaces['EPS']['hasContext'], context.id))
observations.append(objct_detection)

# Link to context
detection = _link_detections(self, context, objct, prdt)
observations.append(detection)

# Open ended learning
learnable_type = self._rdf_builder.create_resource_uri('N2MU',
Expand All @@ -81,18 +90,17 @@ def _create_detections(self, cntxt, context):
# Detections: faces
for item in cntxt.people:
if item.name.lower() != item.UNKNOWN.lower():
# Create and link detection to instance graph
# Create instance
prsn = self._rdf_builder.fill_entity(casefold_text(item.name, format='triple'), ['person', 'Instance'],
'LW')
instances.append(prsn)

# Link detection to graph
_link_entity(self, prsn, self.instance_graph)
# Bidirectional link to context
self.interaction_graph.add((context.id, self.namespaces['EPS']['hasDetection'], prsn.id))
self.instance_graph.add((prsn.id, self.namespaces['EPS']['hasContext'], context.id))
# Create detection
face_detection = create_claim_graph(self, self.myself, prdt, prsn, UtteranceType.EXPERIENCE)
self.claim_graph.add((face_detection.id, self.namespaces['EPS']['hasContext'], context.id))
observations.append(face_detection)
instances.append(prsn)

# Link to context
detection = _link_detections(self, context, prsn, prdt)
observations.append(detection)

return instances, observations

Expand Down
4 changes: 2 additions & 2 deletions test/brain/location disambiguation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pepper.brain import LongTermMemory
from test.brain.utils import transform_capsule, places, binary_values, capsule_likes, capsule_is_from, capsule_is_from_2, \
from test.brain.utils import transform_capsule, places, binary_values, capsule_is_from, capsule_is_from_2, \
capsule_is_from_3, capsule_knows

from random import choice
Expand All @@ -9,7 +9,7 @@
# Create brain connection
brain = LongTermMemory(clear_all=True)

capsules = [capsule_likes, capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows]
capsules = [capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows]

for capsule in capsules:
say = ''
Expand Down
27 changes: 4 additions & 23 deletions test/brain/phrasing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pepper.language.generation.thoughts_phrasing import phrase_thoughts
from pepper.brain import LongTermMemory

from test.brain.utils import transform_capsule, binary_values, capsule_likes, capsule_is_from, capsule_is_from_2, \
from test.brain.utils import transform_capsule, binary_values, capsule_is_from, capsule_is_from_2, \
capsule_is_from_3, capsule_knows

from random import choice
Expand All @@ -11,7 +11,7 @@
# Create brain connection
brain = LongTermMemory(clear_all=True)

capsules = [capsule_likes, capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows]
capsules = [capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows]

for capsule in capsules:
say = ''
Expand All @@ -21,24 +21,5 @@
capsule = transform_capsule(capsule, empty=em, no_people=np, place=p)
x = brain.update(capsule, reason_types=True)

print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
print(phrase_thoughts(x, True, True))
for x in range(10):
print(phrase_thoughts(x, True, True))
30 changes: 6 additions & 24 deletions test/brain/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pepper.language.generation.thoughts_phrasing import phrase_thoughts
from pepper.brain import LongTermMemory

from test.brain.utils import transform_capsule, places, binary_values, capsule_likes, capsule_is_from, capsule_is_from_2, \
from test.brain.utils import transform_capsule, places, binary_values, capsule_is_from, capsule_is_from_2, \
capsule_is_from_3, capsule_knows

from random import choice
Expand All @@ -10,8 +11,8 @@
# Create brain connection
brain = LongTermMemory(clear_all=True)

capsules = [capsule_likes, capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows, capsule_likes,
capsule_likes, capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows, capsule_likes]
capsules = [capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows,
capsule_is_from, capsule_is_from_2, capsule_is_from_3, capsule_knows]

for capsule in capsules:
say = ''
Expand All @@ -37,27 +38,8 @@
say += 'Having a talk at %s' % capsule.context.location.label
print(say)

# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
# print(phrase_thoughts(x, True, True))
for x in range(10):
print(phrase_thoughts(x, True, True))

# for x in range(10):
# say = ''
Expand Down
8 changes: 4 additions & 4 deletions test/language/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def test_scenario(statement, questions, gold):
'''
correct = 0
chat = Chat("Lenka", fake_context())
brain = LongTermMemory()
# clear_all=True) # WARNING! this deletes everything in the brain, must only be used for testing
# WARNING! this deletes everything in the brain, must only be used for testing
brain = LongTermMemory(clear_all=False)

# one or several statements are added to the brain
if ',' in statement:
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_with_triples(path):

test_files = ["./data/statements.txt"]

for test_file in all_test_files:
test_with_triples(test_file)
# for test_file in all_test_files:
# test_with_triples(test_file)

test_scenarios()

0 comments on commit 233d39d

Please sign in to comment.