~kamstrup/zeitgeist/query-expansion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
====================================
How are symbols handled in zeitgeist
====================================

What are symbols and how are they used
**************************************

The datamodel provides two top-level symbols, 'Manifestation' and
'Interpretation'. These symbols are part of the python representation
of the zeitgeist ontologie and several other ontologies.

    >>> from zeitgeist.datamodel import Manifestation, Interpretation
    >>> print repr(Manifestation)
    <Manifestation 'Manifestation'>
    >>> print repr(Interpretation)
    <Interpretation 'Interpretation'>
    
How do Symbols work?
********************

To answer this question we will build up our own set of Symbols from
scratch.

    >>> from zeitgeist.datamodel import Symbol
    >>> TestSymbol = Symbol(name="Test", uri="http://some/uri#TestSymbol")
    >>> print repr(TestSymbol)
    <Test 'http://some/uri#TestSymbol'>
    
    >>> TestSymbol.get_children()
    frozenset([])
    >>> TestSymbol.get_parents()
    frozenset([])
    
Now it is possible to register another symbol which is a sub-symbol of
`TestSymbol`
    
    >>> Symbol("SubSymbol", parent=set([TestSymbol,]), uri="http://some_other/uri#SubSymbol")
    <SubSymbol 'http://some_other/uri#SubSymbol'>
    >>> TestSymbol.SubSymbol
    <SubSymbol 'http://some_other/uri#SubSymbol'>
    
Now let's see how getting children of a symbol works

    >>> sorted(TestSymbol.get_children())
    [<SubSymbol 'http://some_other/uri#SubSymbol'>]
    >>> sorted(TestSymbol.get_all_children())
    [<Test 'http://some/uri#TestSymbol'>, <SubSymbol 'http://some_other/uri#SubSymbol'>]
    
Getting sub symbols by uri:

    >>> TestSymbol["http://some_other/uri#SubSymbol"]
    <SubSymbol 'http://some_other/uri#SubSymbol'>
    
Symbol names must be CamelCase

    >>> TestSymbol.somesymbol
    Traceback (most recent call last):
        ...
    AttributeError: 'Symbol' object has no attribute 'somesymbol'

    >>> Symbol("somesymbol", parent=set([TestSymbol,]))
    Traceback (most recent call last):
        ...
    ValueError: Naming convention requires symbol name to be CamelCase, got 'somesymbol'

If you want to create a sub symbol, but you are not sure if the parent symbol
exists at this time you can give either the uri or the name of the parent
symbol as name to avoid NameErrors:

    >>> Symbol("AnotherTest", parent=set(["Interpretation",]))
    <AnotherTest 'AnotherTest'>
    >>> print Interpretation.AnotherTest
    AnotherTest
    >>> Symbol("JustAnotherTest",
    ...     parent=set(["http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#MindMap",]))
    <JustAnotherTest 'JustAnotherTest'>
    >>> print Interpretation.MindMap.JustAnotherTest
    JustAnotherTest
    
Symbols are also lazy wrt. attribute lookup, you can get each symbol by
using it as an attribute of the top-level symbol

    >>> Interpretation.Document.MindMap.JustAnotherTest == \
    ...     Interpretation.MindMap.JustAnotherTest == Interpretation.JustAnotherTest
    True