Beispiel #1
0
kb.store('knows(tom, other4)')
kb.store('lives_in(shamala, bay_area)')
kb.store('lives_in(mary, seattle)')
kb.store('associated_with(zillow, amazon)')
kb.store('associated_with(primer, google)')
kb.store('associated_with(amazon, zillow)')
kb.store('associated_with(google, primer)')
kb.store('associated_with(amazon, microsoft)')
kb.store('associated_with(google, facebook)')
kb.store('based_in(microsoft, seattle)')
kb.store('based_in(facebook, bay_area)')

# # # # # # # # # # # # # # # # # # # # # # # #
# Test using node attributes in NN
# # # # # # # # # # # # # # # # # # # # # # # #
kb.attr('tom', {'owns_a_raincoat': 0.0, 'doesnt_own_raincoat': 1.0})
kb.attr('todd', {'owns_a_raincoat': 0.0, 'doesnt_own_raincoat': 1.0})
kb.attr('oleg', {'owns_a_raincoat': 0.0, 'doesnt_own_raincoat': 1.0})
kb.attr('john', {'owns_a_raincoat': 0.0, 'doesnt_own_raincoat': 1.0})
kb.attr('akshay', {'owns_a_raincoat': 0.0, 'doesnt_own_raincoat': 1.0})
kb.attr('vedant', {'owns_a_raincoat': 0.0, 'doesnt_own_raincoat': 1.0})
kb.attr('other1', {'owns_a_raincoat': 1.0, 'doesnt_own_raincoat': 0.0})
kb.attr('other2', {'owns_a_raincoat': 1.0, 'doesnt_own_raincoat': 0.0})
kb.attr('other3', {'owns_a_raincoat': 1.0, 'doesnt_own_raincoat': 0.0})
kb.attr('other4', {'owns_a_raincoat': 1.0, 'doesnt_own_raincoat': 0.0})
kb.attr('other5', {'owns_a_raincoat': 1.0, 'doesnt_own_raincoat': 0.0})
kb.attr('other6', {'owns_a_raincoat': 1.0, 'doesnt_own_raincoat': 0.0})

kb.build_kg_model(cuda=False,
                  embedding_size=30,
                  node_attributes=['owns_a_raincoat', 'doesnt_own_raincoat'],
Beispiel #2
0
import context

from zincbase import KB

kb = KB()
kb.seed(555)

kb.store('person(tom)')
kb.store('person(shamala)')
kb.store('knows(tom, shamala)')
assert kb.neighbors('tom') == [('shamala', [{'pred': 'knows'}])]

kb.attr('tom', {'grains': 0})

tom = kb.node('tom')
assert tom.grains == 0
assert tom.i_dont_exist is None
assert tom['i_dont_exist'] is None

kb.attr('shamala', {'grains': 4})
shamala = kb.node('shamala')
assert shamala.grains == 4
shamala.grains += 1
assert shamala.grains == 5
assert shamala['grains'] == 5
shamala['grains'] += 1
assert shamala['grains'] == 6

kb.store('person(jeraca)')
kb.attr('jeraca', {'grains': 3})
Beispiel #3
0
import context

from zincbase import KB

kb = KB()
kb.store('a(b,c)')
kb.attr('b', {'is_letter': 1.0})
assert kb.node('b') == {'is_letter': 1.0}
kb.edge_attr('b', 'a', 'c', {'both_alpha': 1.0})
assert kb.edge('b', 'a', 'c') == {'both_alpha': 1.0}
assert kb.to_triples() == [('b', 'a', 'c')]
triples = kb.to_triples(data=True)
assert triples == [('b', 'a', 'c', {'is_letter': 1.0}, {'both_alpha': 1.0}, {}, False)]
kb.attr('c', {'is_letter': 0.9})
triples = kb.to_triples(data=True)
assert triples == [('b', 'a', 'c', {'is_letter': 1.0}, {'both_alpha': 1.0}, {'is_letter': 0.9}, False)]
neg_rule_idx = kb.store('~a(b,c)')
triples = kb.to_triples(data=True)
assert triples == [('b', 'a', 'c', {'is_letter': 1.0}, {'both_alpha': 1.0}, {'is_letter': 0.9}, True)]
kb.delete_rule(neg_rule_idx)
triples = kb.to_triples(data=True)
assert triples == [('b', 'a', 'c', {'is_letter': 1.0}, {'both_alpha': 1.0}, {'is_letter': 0.9}, False)]
kb.edge_attr('b', 'a', 'c', {'truthiness':-1})
triples = kb.to_triples(data=True)
assert triples == [('b', 'a', 'c', {'is_letter': 1.0}, {'both_alpha': 1.0, 'truthiness': -1}, {'is_letter': 0.9}, True)]
kb.delete_edge_attr('b', 'a', 'c', ['truthiness'])
triples = kb.to_triples(data=True)
assert triples == [('b', 'a', 'c', {'is_letter': 1.0}, {'both_alpha': 1.0}, {'is_letter': 0.9}, False)]
print('All graph tests passed.')