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

Subscribers

People subscribed via source and target branches