Skip to content

Commit

Permalink
updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Feb 15, 2024
1 parent d3626ef commit bed6ad0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions examples/sampling_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ontosample.classic_samplers import *
from ontosample.lpc_samplers import *
from ontosample.lpf_samplers import *
from ontolearn.knowledge_base import KnowledgeBase
from ontolearn_light.knowledge_base import KnowledgeBase

# 0. Load json that stores the learning problem
with open("learning_problems/uncle_lp.json") as json_file:
Expand All @@ -14,16 +14,18 @@
print(f'Initial individuals: {kb.individuals_count()}')

# 2. Initialize learning problem (required only for LPF and LPC samplers)
# This does not necessarily need to be the set of learning problem nodes. It can be any set of nodes that you want to
# certainly include in the sample (LPF) or have the sample graph centralized at them (LPC).
pos = set(map(OWLNamedIndividual, map(IRI.create, set(examples['positive_examples']))))
neg = set(map(OWLNamedIndividual, map(IRI.create, set(examples['negative_examples']))))
lp = pos.union(neg)

# 3. Initialize the sampler and generate the sample
sampler = RandomWalkerJumpsSamplerLPCentralized(kb, lp)
sampled_kb = sampler.sample(30)
sampled_kb = sampler.sample(30) # will generate a sample with 30 nodes

print(f'Removed individuals: {len(sampler.get_removed_nodes())}')
print(f'Removed individuals: {kb.individuals_count() - sampled_kb.individuals_count()}')
print(f'Remaining individuals: {sampled_kb.individuals_count()}')

# 4. Save the sampled ontology
sampler.save_sample()
# 4. Save the sampled ontology into a file named 'sampled_kb' (this file will be created on runtime)
sampler.save_sample(sampled_kb, 'sampled_kb')

0 comments on commit bed6ad0

Please sign in to comment.