Merge lp:~zeitgeist/zeitgeist/symbols into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Seif Lotfy
Status: Merged
Merged at revision: 73
Proposed branch: lp:~zeitgeist/zeitgeist/symbols
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 144 lines (+118/-0)
3 files modified
src/Makefile.am (+1/-0)
src/ontology.vala (+116/-0)
src/zeitgeist-daemon.vala (+1/-0)
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/symbols
Reviewer Review Type Date Requested Status
Michal Hruby (community) Needs Fixing
Siegfried Gevatter Needs Fixing
Review via email: mp+69927@code.launchpad.net

Description of the change

Symbols class for generating symbols that will be used later for Interpretation and Manifestation

To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote :

 - /* datamodel.vala
ontology

 - public static HashTable<string, Symbol> SymbolsCollection = null;
rename all_symbols, put it into Symbol (it's static), make it private

 - displayName, allChildren
display_name, all_children

 - why are you messing with GenericArray<->List? (parents, etc.)
they're the same, so use just one

 - doesn't work when it isn't a direct parent.
you need to lookup the parent in all_symbols (formerly SymbolsCollection)
then iterate over its all_children

 - make the constructor private and let register take the uri/name/etc and
instantiate (later we'll also hide register in some way, eg. making it
protected).

 - we need a "static Symbol from_uri(sting uri)" which returns
"all_symbols.lookup(uri)".

review: Needs Fixing
Revision history for this message
Michal Hruby (mhr3) wrote :

I find the Symbol class just an implementation detail, there's no need to expose it at all, as RainCT said you'll want to use static functions with signature like `string[] Symbol.get_children (string uri)`, or `string Symbol.get_description (string uri)` (of course we can use different container, not just array of strings, but ultimately why not make it simple - the only reason that comes to mind would be API compatibility with current libzg).

review: Needs Fixing
Revision history for this message
Seif Lotfy (seif) wrote :

> - /* datamodel.vala
> ontology
>
> - public static HashTable<string, Symbol> SymbolsCollection = null;
> rename all_symbols, put it into Symbol (it's static), make it private
>

why put it in symbol?

> - displayName, allChildren
> display_name, all_children

ok

>
> - why are you messing with GenericArray<->List? (parents, etc.)
> they're the same, so use just one

ok i will go with string[]

>
> - doesn't work when it isn't a direct parent.
> you need to lookup the parent in all_symbols (formerly SymbolsCollection)
> then iterate over its all_children

what doesnt work? in case of get_parents it will work since upon construction u already pass the parent classes as an argument...

>
> - make the constructor private and let register take the uri/name/etc and
> instantiate (later we'll also hide register in some way, eg. making it
> protected).
>
> - we need a "static Symbol from_uri(sting uri)" which returns
> "all_symbols.lookup(uri)".

ok

lp:~zeitgeist/zeitgeist/symbols updated
63. By Seif Lotfy

changed namings from camelCase to camel_case and added new method from_uri and move SymbolcsCollection into the Symbol class

64. By Seif Lotfy

updated to trunk

65. By Seif Lotfy

merged and updated get_parents and get_children

66. By Seif Lotfy

Change generic arrays to lists in ontology.vala, also make get_parents and get_all_children return strings instead of symbols

67. By Seif Lotfy

removed all_children property and fixed the unowned issue

Revision history for this message
Michal Hruby (mhr3) wrote :

Since you made get_parents return all parents, there's now no way to get the immediate parents and therefore reconstruct the original ontology graph easily. Fix pls...

review: Needs Fixing
Revision history for this message
Seif Lotfy (seif) wrote :

you can get the immidiate stuff by asking for the properties, parents and
children...
I will just change the names to get_all_parents

On Mon, Aug 1, 2011 at 1:55 PM, Michal Hruby <email address hidden> wrote:

> Review: Needs Fixing
> Since you made get_parents return all parents, there's now no way to get
> the immediate parents and therefore reconstruct the original ontology graph
> easily. Fix pls...
> --
> https://code.launchpad.net/~zeitgeist/zeitgeist/symbols/+merge/69927
> Your team Zeitgeist Framework Team is subscribed to branch
> lp:~zeitgeist/zeitgeist/bluebird.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~zeitgeist
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~zeitgeist
> More help : https://help.launchpad.net/ListHelp
>

lp:~zeitgeist/zeitgeist/symbols updated
68. By Seif Lotfy

removed unneccesary string

Revision history for this message
Michal Hruby (mhr3) wrote :

My point is that the Symbol class itself shouldn't even be public, it should be something private to this source file.

Method that this file needs to expose are (all of them are static):

List<string> Symbol.get_parents (string uri)
List<string> Symbol.get_children (string uri)
List<string> Symbol.get_all_children (string uri)
bool Symbol.is_a (string uri, string parent_uri)

string Symbol.get_display_name (string uri)
string Symbol.get_... (string uri)

and of course to make all of this usable:
void Symbol.register(string uri, string display_name, string[] parents, ...)

review: Needs Fixing
lp:~zeitgeist/zeitgeist/symbols updated
69. By Seif Lotfy

changed symbol methods to be static

70. By Seif Lotfy

hide symbol

71. By Seif Lotfy

added get_parents and get_children

72. By Seif Lotfy

changed all methods to be static and no more properties and added get_display_name method

73. By Seif Lotfy

updated to trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2011-08-02 01:21:22 +0000
3+++ src/Makefile.am 2011-08-02 12:36:46 +0000
4@@ -27,6 +27,7 @@
5 table-lookup.vala \
6 sql-schema.vala \
7 where-clause.vala \
8+ ontology.vala \
9 $(NULL)
10
11 bluebird_LDADD = \
12
13=== added file 'src/ontology.vala'
14--- src/ontology.vala 1970-01-01 00:00:00 +0000
15+++ src/ontology.vala 2011-08-02 12:36:46 +0000
16@@ -0,0 +1,116 @@
17+/* datamodel.vala
18+ *
19+ * Copyright © 2011 Collabora Ltd.
20+ * By Seif Lotfy <seif@lotfy.com>
21+ *
22+ * This program is free software: you can redistribute it and/or modify
23+ * it under the terms of the GNU Lesser General Public License as published by
24+ * the Free Software Foundation, either version 2.1 of the License, or
25+ * (at your option) any later version.
26+ *
27+ * This program is distributed in the hope that it will be useful,
28+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+ * GNU General Public License for more details.
31+ *
32+ * You should have received a copy of the GNU Lesser General Public License
33+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
34+ *
35+ */
36+
37+private class Symbol
38+{
39+ private static HashTable<string, Symbol> all_symbols = null;
40+ private List<string> parents;
41+ private List<string> children;
42+ private List<string> all_children;
43+ private string uri;
44+ private string display_name;
45+
46+ private Symbol(string uri, string display_name, string[] parents,string[] children){
47+ this.uri = uri;
48+ this.display_name = display_name;
49+ this.parents = new List<string>();
50+ for (int i = 0; i < parents.length; i++)
51+ this.parents.append(parents[i]);
52+ this.children = new List<string>();
53+ for (int i = 0; i < children.length; i++)
54+ this.children.append(children[i]);
55+ }
56+
57+ public static string get_display_name(string symbol_uri)
58+ {
59+ var symbol = all_symbols.lookup(symbol_uri);
60+ return symbol.display_name;
61+ }
62+
63+ public static List<string> get_all_parents(string symbol_uri)
64+ {
65+ var symbol = all_symbols.lookup(symbol_uri);
66+ var results = new List<string>();
67+ foreach (string uri in symbol.parents)
68+ {
69+ results.append(uri);
70+ var parent = all_symbols.lookup(uri);
71+ // Recursivly get the other parents
72+ foreach (string s in get_all_parents(uri))
73+ if (results.index(s) > -1)
74+ results.append(s);
75+ }
76+ return results;
77+ }
78+
79+ public static List<string> get_all_children(string symbol_uri)
80+ {
81+ var results = new List<string>();
82+ var symbol = all_symbols.lookup(symbol_uri);
83+ foreach (string uri in symbol.all_children)
84+ results.append(uri);
85+ return results;
86+ }
87+
88+ public static List<string> get_children(string symbol_uri)
89+ {
90+ var results = new List<string>();
91+ var symbol = all_symbols.lookup(symbol_uri);
92+ foreach (string uri in symbol.children)
93+ results.append(uri);
94+ return results;
95+ }
96+
97+ public static List<string> get_parents(string symbol_uri)
98+ {
99+ var results = new List<string>();
100+ var symbol = all_symbols.lookup(symbol_uri);
101+ foreach (string uri in symbol.parents)
102+ results.append(uri);
103+ return results;
104+ }
105+
106+ public static bool is_a(string symbol_uri, string parent_uri)
107+ {
108+ foreach (string uri in get_all_parents(symbol_uri))
109+ if (parent_uri == uri)
110+ return true;
111+ return false;
112+ }
113+
114+ public static void register(string uri, string display_name, string[] parents,
115+ string[] children)
116+ {
117+ if (all_symbols == null)
118+ all_symbols = new HashTable<string, Symbol>(str_hash, str_equal);
119+ Symbol symbol = new Symbol(uri, display_name, parents, children);
120+ all_symbols.insert(uri, symbol);
121+ }
122+
123+ public static Symbol from_uri(string uri)
124+ {
125+ return all_symbols.lookup(uri);
126+ }
127+
128+ public string to_string()
129+ {
130+ return this.uri;
131+ }
132+}
133
134=== modified file 'src/zeitgeist-daemon.vala'
135--- src/zeitgeist-daemon.vala 2011-07-31 17:41:19 +0000
136+++ src/zeitgeist-daemon.vala 2011-08-02 12:36:46 +0000
137@@ -3,6 +3,7 @@
138 * Copyright © 2011 Seif Lotfy <seif@lotfy.com>
139 * Copyright © 2011 Collabora Ltd.
140 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
141+ * By Seif Lotfy <seif@lotfy.com>
142 *
143 * This program is free software: you can redistribute it and/or modify
144 * it under the terms of the GNU Lesser General Public License as published by

Subscribers

People subscribed via source and target branches