1 # This Python file uses the following encoding: utf-8
3 Created on Apr 29, 2011
8 class OntologyBuilderFramework(object):
9 """A framework for building domain ontologies, assuming that the framework for doing such is:
10 C{TERMS}: identify terms (from a corpus or such)
11 C{SYNONYMS}: identify synonyms amongst the terms
12 C{CONCEPTS}: identify concepts
13 C{CONCEPT_HIERARCHIES}: identify heirarchical relationships amongst concepts
14 C{RELATIONS}: identify other relationships amongst concepts
20 CONCEPT_HIERARCHIES
="concept_hierarchies"
23 def __init__(self
, name
, initial_state
={}, only_do
=None):
25 @type initial_state: C{dict}
26 @param initial_state: additional state available when processing with a framework instance
28 @param name: the name of this framework instance (used debuggin)
29 @type cachedir: C{str}
30 @param cachedir: the base directory in which to cache the ontology generation process
32 self
.__state
= initial_state
34 self
.__only
_do
= only_do
38 get the current state.
46 get the name of the framework instance.
52 def _do_step(self
, step
):
54 returns C{True} if the framework instance is designed to perform step C{step}
58 if self
.__only
_do
and step
not in self
.__only
_do
:
62 def __get_initial_state(self
, additional_state
):
64 construct a state collection given the defaults for object,
65 and anything additional supplied for the specific run.
67 state
= self
.state().copy()
68 state
.update(additional_state
)
71 def process(self
, **additional_state
):
73 iterate through predefined to construct an ontology.
75 @return the resulting state
78 state
= self
.__get
_initial
_state
(additional_state
)
80 for step
in (OntologyBuilderFramework
.TERMS
,
81 OntologyBuilderFramework
.SYNONYMS
,
82 OntologyBuilderFramework
.CONCEPTS
,
83 OntologyBuilderFramework
.CONCEPT_HIERARCHIES
,
84 OntologyBuilderFramework
.RELATIONS
):
86 if self
._do
_step
(step
):
87 result
= self
.__getattribute
__('_get_%s' % step
)(**state
)
90 raise Exception("no result (%s) at step %s" % (result
, step
))
93 print "found %s %s" % (len(result
), step
)
97 class OntologyBuilderTerms(object):
98 """interface for building terms for an ontology"""
99 def _get_terms(self
, **state
):
102 class OntologyBuilderSynonyms(object):
103 """interface for building synonyms (usually of terms) for an ontology"""
104 def _get_synonyms(self
, **state
):
107 class OntologyBuilderConcepts(object):
108 """interface for constructing concepts for an ontology"""
109 def _get_concepts(self
, **state
):
112 class OntologyBuilderConceptHierarchies(object):
113 """interafce for constructing hierarchies of concepts for an ontology"""
114 def _get_concept_hierarchies(self
, **state
):
117 class OntologyBuilderRelations(object):
118 """interface for building relations between concepts in an ontology"""
119 def _get_relations(self
, **state
):