~ubuntu-branches/ubuntu/hardy/steam/hardy

« back to all changes in this revision

Viewing changes to server/libraries/Visconte.pmod/Request.pmod/Action.pmod

  • Committer: Bazaar Package Importer
  • Author(s): Alain Schroeder
  • Date: 2006-11-21 16:03:12 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061121160312-nf96y6nihzsyd2uv
Tags: 2.2.31-3
Add patch to prevent inconsistent data after shutdown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 import Visconte;
 
2
// import Visconte.Onto;
 
3
// import Visconte.Onto.Item;
 
4
// import Visconte.Request;
 
5
 
 
6
class GenericAction
 
7
//{{{ 
 
8
{
 
9
 
 
10
/**
 
11
 * <p>class Action - A generic action which should  not be instanciated at all. Use the dynamic binding instead and define
 
12
 * sublcasses for new actions from this class. e.g GenericAction a = ClassAcion() </p>
 
13
 * Most of the Methods will return an Visconte.Request.Result object, which can be used for xml rendering and finding errors
 
14
 */
 
15
 
 
16
 
 
17
/**
 
18
 * <p>The type of the action, subclasses should  overwrite this value with its action type, e.g for ClassAction use class etc.</p>
 
19
 */
 
20
    public constant action_type ="GENERICACTION";
 
21
 
 
22
 
 
23
/**
 
24
 * <p>the language of the ontology retrieval</p>
 
25
 */
 
26
    protected string lang = "en";
 
27
 
 
28
/**
 
29
 * <p>The ontology object</p>
 
30
 */
 
31
    protected Visconte.Onto.Ontology ontology;
 
32
 
 
33
/**
 
34
 * <p>The Visconte.Onto.Item.OWLItem Factory to produce items</p>
 
35
 */
 
36
    protected Visconte.Onto.OWLItemFactory factory = Visconte.Onto.OWLItemFactory();
 
37
 
 
38
/**
 
39
 * <p>construcor of the specified action. Use it in dynamic binding style, e.g Action a = ClassAction(...) </p>
 
40
 * 
 
41
 * 
 
42
 * @param ontology the ontology
 
43
 *
 
44
 */
 
45
    public void create(Visconte.Onto.Ontology ontology) 
 
46
    {        
 
47
       this_program::ontology = ontology;
 
48
      
 
49
    } 
 
50
    
 
51
/**
 
52
 * <p>get a specific item</p>
 
53
 * 
 
54
 * 
 
55
 * @param ID id - the id of the item to get 
 
56
 * @return Visconte.Request.Result - the item
 
57
 */
 
58
    public Visconte.Request.Result get_Item(ID id)
 
59
    {        
 
60
       
 
61
            
 
62
       Visconte.Request.Result res = Visconte.Request.Result();
 
63
       Visconte.Onto.Item.OWLItem owl_item;
 
64
       array error =catch
 
65
       {
 
66
               if(ontology->item_exists(id->ref))
 
67
               {
 
68
                       owl_item = ontology->get_Item(id->ref);
 
69
               }
 
70
               else
 
71
                       res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, id->ref }) ));
 
72
       };
 
73
       if(error)
 
74
               res->add_Message(Visconte.Request.Message(error));
 
75
       
 
76
       res->set_OWLItem(owl_item);
 
77
       
 
78
       return res;
 
79
               
 
80
               
 
81
    } 
 
82
    
 
83
/**
 
84
 * <p>get a specific item</p>
 
85
 * 
 
86
 * 
 
87
 * @param ID id - the id of the item to get 
 
88
 * @return Visconte.Onto.Item.OWLItem - the item as object
 
89
 */
 
90
    public Visconte.Onto.Item.OWLItem get_RawItem(ID id)
 
91
    {        
 
92
       Visconte.Onto.Item.OWLItem owl_item;
 
93
       array error =catch
 
94
       {
 
95
               if(ontology->item_exists(id->ref))
 
96
               {
 
97
                       return ontology->get_Item(id->ref);
 
98
               }
 
99
               else
 
100
                       return 0;
 
101
       };
 
102
      
 
103
    } 
 
104
    
 
105
/**
 
106
 * <p>Changes the name of any OWLItem
 
107
 * 
 
108
 * 
 
109
 * @param ID id - current id of the item to rename 
 
110
 * @param label - the new label of the item
 
111
 * @param string comment - a comment for the ontology log
 
112
 * @return Result - the renamed item
 
113
 */
 
114
    public Visconte.Request.Result rename(ID id, mapping label, string comment) 
 
115
    {
 
116
        Visconte.Request.Result res = Visconte.Request.Result(); 
 
117
        Visconte.Onto.Item.OWLItem  item;
 
118
        string oldname;
 
119
        
 
120
        array error=catch
 
121
        {
 
122
                    item = ontology->get_Item(id->ref); 
 
123
                    oldname= item->get_Label();
 
124
                    item->set_Label(label);
 
125
                    ontology->update(item);
 
126
        };
 
127
        
 
128
        if(error)
 
129
                res->add_Message(Visconte.Request.Message(error));
 
130
        else
 
131
        {
 
132
                string action;
 
133
                switch(item->ITEMTYPE)
 
134
                {
 
135
                //if class
 
136
                case Visconte.Onto.Item.OWLItem.CLASS:
 
137
                action = "class_renamed";
 
138
                break;
 
139
                
 
140
                case Visconte.Onto.Item.OWLItem.OBJECT_PROPERTY:
 
141
                action = "association_renamed";
 
142
                break;
 
143
                
 
144
                case Visconte.Onto.Item.OWLItem.DATATYPE_PROPERTY:
 
145
                action = "datatype_renamed";
 
146
                break;
 
147
                
 
148
                case Visconte.Onto.Item.OWLItem.INDIVIDUAL:
 
149
                action = "individual_renamed";
 
150
                break;
 
151
                
 
152
                default:
 
153
                action = "unspecified_item_renamed";
 
154
                break;
 
155
                
 
156
                }
 
157
                ontology->add_annotation(item,action,(string)comment,oldname);
 
158
        }
 
159
        res->set_OWLItem(item);
 
160
        return res;
 
161
                    
 
162
    }
 
163
 
164
    
 
165
    
 
166
    
 
167
 
 
168
/**
 
169
 * <p>class ClassAction - Class related Actions take place in here</p>
 
170
 */    
 
171
class ClassAction
 
172
{
 
173
inherit GenericAction;
 
174
 
 
175
 
 
176
/**
 
177
 * <p>move a class to a new location.</p>
 
178
 * 
 
179
 * 
 
180
 * @param id the id of the class
 
181
 * @param new_parent the parent id where this class should be moved
 
182
 * @param with_subtree indicate if the subtree should be moved too
 
183
 * @param string comment - a comment for the ontology log
 
184
 * @return 
 
185
 */
 
186
    public Visconte.Request.Result move(ID class_id, ID new_parent_id, string comment) 
 
187
    {    
 
188
        Visconte.Request.Result res = Visconte.Request.Result(); 
 
189
        string move_class_label="";
 
190
        Visconte.Onto.Item.OWLItem  move_class;
 
191
        Visconte.Onto.Item.OWLItem  new_parent;
 
192
        
 
193
        if(ontology->item_exists(class_id->ref) && ontology->item_exists(new_parent_id->ref))
 
194
        {
 
195
                
 
196
                array error = catch{
 
197
                        move_class = ontology->get_Item(class_id->ref);
 
198
                        move_class_label=move_class->get_Label();
 
199
                        new_parent = ontology->get_Item(new_parent_id->ref);
 
200
                        //test for a possible move to a child of itself
 
201
                        if(new_parent->is_descendant_of(move_class->get_Id()))
 
202
                        {
 
203
                                 res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 221, class_id->ref }) ));
 
204
                        }
 
205
                        else
 
206
                        {
 
207
                                move_class->set_parent(ontology->get_Item(new_parent_id->ref));
 
208
                                ontology->update(move_class);
 
209
                        }
 
210
                };
 
211
                res->set_OWLItem(move_class);
 
212
                if(error)
 
213
                        res->add_Message(Visconte.Request.Message(error));
 
214
                else
 
215
                        ontology->add_annotation(move_class_label,"class_moved",(string)comment,new_parent->get_Label());
 
216
        }
 
217
        //check what not exists
 
218
        else
 
219
        {
 
220
                if(!ontology->item_exists(class_id->ref))
 
221
                 res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, class_id->ref }) ));
 
222
                if(!ontology->item_exists(new_parent_id->ref))
 
223
                 res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, new_parent_id->ref }) ));
 
224
        }
 
225
        return res;
 
226
    } 
 
227
 
 
228
/**
 
229
 * <p>Add a new class to the ontology</p>
 
230
 * 
 
231
 * 
 
232
 * @param ID new_id - the new id of the subclass
 
233
 * @param ID parent_id - the id this class should be subclass of
 
234
 * @param label - mapping with name value pairs: e.g. en->class, de->klasse etc 
 
235
 * @param string comment - a comment for the ontology log
 
236
 * @return 
 
237
 */
 
238
    public Visconte.Request.Result subclass(ID new_id, ID parent_id, mapping label, array equivalent_Class, array different_From , string comment) 
 
239
    {        
 
240
        Visconte.Request.Result res = Visconte.Request.Result(); 
 
241
        Visconte.Onto.Item.OWLItem  new_class;
 
242
        
 
243
        array error=catch
 
244
        {
 
245
                    new_class = factory->construct_Class(ontology,new_id,parent_id,label, equivalent_Class,  different_From,);
 
246
                    ontology->add_Item(new_class);
 
247
                    new_class->mirror_restrictions();
 
248
                 
 
249
                    
 
250
                            
 
251
        };
 
252
        
 
253
        if(error)
 
254
                res->add_Message(Visconte.Request.Message(error));
 
255
        else
 
256
                ontology->add_annotation(new_class,"class_subclassed",(string)comment,parent_id->ref);
 
257
        res->set_OWLItem(new_class);
 
258
        return res;
 
259
        
 
260
        
 
261
    }
 
262
    
 
263
/**
 
264
 * <p>Sets a class as document term for specified object</p>
 
265
 * 
 
266
 * 
 
267
 * @param id the id, the comment should linked with
 
268
 * @param isDocumentTerm is this class a document term
 
269
 * @return 
 
270
 */
 
271
    public int set_as_document_term(ID id,int isDocumentTerm) {        
 
272
        
 
273
        Visconte.Onto.Item.OWLItem i = ontology->get_Item(id->ref);
 
274
        if(i)
 
275
        {
 
276
                ontology->set_as_document_term(i, isDocumentTerm);
 
277
                return 1;
 
278
        }
 
279
    }
 
280
    
 
281
/**
 
282
 * <p>Sets a class as document term for specified object</p>
 
283
 * 
 
284
 * 
 
285
 * @param id the id, the comment should linked with
 
286
 * @param isDocumentTerm is this class a document term
 
287
 * @return 
 
288
 */
 
289
    public int is_document_term(ID id) {        
 
290
        
 
291
        Visconte.Onto.Item.OWLItem i = ontology->get_Item(id->ref);
 
292
        return i->is_document_term();
 
293
    }    
 
294
/**
 
295
 * <p>Delete all classes under this id recursive</p>
 
296
 * 
 
297
 * 
 
298
 * @param ID id the id to delete
 
299
 * @return 1
 
300
 *
 
301
*/
 
302
    private int delete_tree(ID id) 
 
303
    {                                   
 
304
           
 
305
            //first remove all restrictions;
 
306
            set_restrictions(id,0,0,1,"");
 
307
            Visconte.Onto.Item.OWLClass start_class = ontology->get_Item(id->ref);
 
308
            if(!start_class) return 0;
 
309
            
 
310
            if(start_class->has_childs())
 
311
            {
 
312
                    Visconte.Onto.OWLContainer container  = start_class->get_childs();
 
313
                    while(container->has_items())
 
314
                    {
 
315
                            delete_tree(ID(container->next()->get_Id(),1));
 
316
                    }
 
317
            }
 
318
            
 
319
            delete(id,0,"");
 
320
            return 1;
 
321
    }
 
322
            
 
323
            
 
324
/**
 
325
 * <p>Delete a class from the ontology</p>
 
326
 * 
 
327
 * 
 
328
 * @param ID id the id to delete
 
329
 * @param string comment - a comment for the ontology log
 
330
 * @param string comment - a comment for the ontology log
 
331
 * @return Result 
 
332
 *
 
333
*/
 
334
    public Visconte.Request.Result delete(ID id, int with_subtree, string comment) 
 
335
    {       
 
336
            Visconte.Request.Result res = Visconte.Request.Result();
 
337
            Visconte.Onto.Item.OWLClass class_to_remove;
 
338
            string class_label;
 
339
            array error = catch
 
340
            {
 
341
                    //the whole subtree should be deleted go recursive
 
342
                    if(with_subtree)
 
343
                          delete_tree(id);
 
344
                    //delete the class
 
345
                    else
 
346
                    {
 
347
                            //test for the existence of the Class!
 
348
                            if(ontology->item_exists(id->ref))
 
349
                            {
 
350
                                   
 
351
                                    class_to_remove = ontology->get_Item(id->ref);
 
352
                                    class_label=class_to_remove->get_Label();
 
353
                                    //get the parent of this class
 
354
                                   
 
355
                                    Visconte.Onto.Item.OWLClass parent = class_to_remove->get_parent();
 
356
                                    
 
357
                                    //define the containers
 
358
                                    Visconte.Onto.OWLContainer individuals = class_to_remove->get_individuals();
 
359
                                    Visconte.Onto.OWLContainer child_container = class_to_remove->get_childs();
 
360
                                    Visconte.Onto.OWLContainer class_is_domain_cnt = class_to_remove->get_domain_properties();
 
361
                                    Visconte.Onto.OWLContainer class_is_range_cnt = class_to_remove->get_range_properties();
 
362
                                    
 
363
                                    //remove the individuals which have this class as constructor
 
364
                                    while(individuals->has_items())
 
365
                                    {
 
366
                                            Visconte.Onto.Item.OWLIndividual i = individuals->next();
 
367
                                            //get the indivduals pointing with an assocaition to this resp. i
 
368
                                            //and unset this association
 
369
                                            Visconte.Onto.OWLContainer in_associated = ontology->get_items_by_object(i->get_Id(),0,Visconte.Onto.Item.OWLItem.INDIVIDUAL);
 
370
                                            while(in_associated->has_items())
 
371
                                            {
 
372
                                                   Visconte.Onto.Item.OWLIndividual in_individual = in_associated->next();
 
373
                                                   in_individual->remove_associations_with(i);
 
374
                                                   ontology->update(in_individual);
 
375
                                            }
 
376
                                            ontology->remove(i);
 
377
                                    }
 
378
                                    //give the childs a new parent :)
 
379
                                    while(child_container->has_items())
 
380
                                    {
 
381
                                            Visconte.Onto.Item.OWLItem i = child_container->next();
 
382
                                            if(!with_subtree)
 
383
                                            {
 
384
                                                    i->set_parent(parent);
 
385
                                                    ontology->update(i);
 
386
                                            }
 
387
                                            else
 
388
                                                   ontology->remove(i);  
 
389
                                    }
 
390
                                  
 
391
                                    // remove all ObjectProperties where the class act as range
 
392
                                    while(class_is_range_cnt->has_items())
 
393
                                    {
 
394
                                            Visconte.Onto.Item.OWLItem i = class_is_range_cnt->next();
 
395
                                            if(i->ITEMTYPE==Visconte.Onto.Item.OWLItem.OBJECT_PROPERTY)
 
396
                                            {
 
397
                                                    Visconte.Onto.OWLContainer inds_pointing_to_this = i->get_individuals();
 
398
                                                    ontology->remove(i);
 
399
                                            }
 
400
                                    }
 
401
                                    //remove all properties where the class acta as the domain
 
402
                                    while(class_is_domain_cnt->has_items())
 
403
                                    {
 
404
                                            Visconte.Onto.Item.OWLItem i = class_is_domain_cnt->next();
 
405
                                            ontology->remove(i);
 
406
                                    }
 
407
                                    //finally remove the class itself
 
408
                                    ontology->remove(class_to_remove);
 
409
                                    
 
410
                            }
 
411
                            else
 
412
                            {
 
413
                                //not exist message
 
414
                                res->add_Message(Visconte.Request.Message( ({ "", backtrace(),11, id->ref }) )); 
 
415
                            }   
 
416
                                    
 
417
                    }//end if with_subtree
 
418
                   
 
419
            }; //end catch
 
420
            
 
421
            res->set_OWLItem(class_to_remove);
 
422
            if(error)
 
423
                    res->add_Message(Visconte.Request.Message(error));
 
424
            else
 
425
                    ontology->add_annotation(class_label,"class_deleted",(string)comment,0);
 
426
                    
 
427
            return res;
 
428
    } 
 
429
 
 
430
/**
 
431
 * <p>Get individuals which match this (and sub) classes as template</p>
 
432
 * 
 
433
 * 
 
434
 * @param ID class_id - the id of the template class
 
435
 * @param void|int only_this - only return individuals of this class (not the ones of the subclasses)
 
436
 * @param void|int  with_associated - if set, the associated indivudals will be returned, too
 
437
 * @return Visconte.Request.Result - the result
 
438
 *
 
439
*/
 
440
    public Visconte.Request.Result get_matching_individuals(ID class_id, void|int only_this, void|int with_associated) 
 
441
    {
 
442
            Visconte.Request.Result res = Visconte.Request.Result();
 
443
            Visconte.Onto.Item.OWLClass class_ ;
 
444
            Visconte.Onto.OWLContainer ind;
 
445
            array error = catch{
 
446
                    if(ontology->item_exists(class_id->ref))
 
447
                    {
 
448
                            class_ = ontology->get_Item(class_id->ref);
 
449
                            if(only_this)
 
450
                                    ind=class_->get_individuals();
 
451
                            else
 
452
                                    ind=class_->get_individuals_down_to_leaf();
 
453
                            
 
454
                            if(with_associated)
 
455
                            {
 
456
                                    
 
457
                                 Visconte.Onto.OWLContainer associated_individuals =  Visconte.Onto.OWLContainer();
 
458
                                 while(ind->has_items())
 
459
                                 {
 
460
                                        
 
461
                                        associated_individuals->merge(ind->next()->get_associations());
 
462
                                         write(associated_individuals->to_string());
 
463
                                 }
 
464
                                 ind->merge(associated_individuals);
 
465
                                 ind->reset_iterator();
 
466
                            }
 
467
                    }
 
468
                    else
 
469
                    {
 
470
                        //set a not existing error
 
471
                        res->add_Message(Visconte.Request.Message( ({ "", backtrace(),11, class_id->ref }) ));
 
472
 
 
473
                    }
 
474
                            
 
475
            };
 
476
            if(error)
 
477
                res->add_Message(Visconte.Request.Message(error));
 
478
                
 
479
                res->set_OWLContainer(ind);
 
480
        
 
481
        return res;
 
482
    }
 
483
 
 
484
/**
 
485
 * <p>Get all associations of the given class (and its parents) is pointing to resp. is domain of</p>
 
486
 * 
 
487
 * @param ID class_id - the class id of the domain
 
488
 * @param int|void only_this - if set the inherited associations will not be included 
 
489
 * @return 
 
490
 * @param id the id to delete
 
491
 *
 
492
*/
 
493
    public Visconte.Request.Result get_all_associations(ID class_id, void|int only_this) 
 
494
    {
 
495
            Visconte.Request.Result res = Visconte.Request.Result();
 
496
            Visconte.Onto.Item.OWLClass class_ ;
 
497
            Visconte.Onto.OWLContainer assoc;
 
498
            array error = catch{
 
499
                    if(ontology->item_exists(class_id->ref))
 
500
                    {
 
501
                            class_ = ontology->get_Item(class_id->ref);
 
502
                            if(only_this)
 
503
                                    assoc=class_->get_domain_properties();
 
504
                            else
 
505
                                    assoc=class_->get_inherited_domain_properties();
 
506
                    }
 
507
                    else
 
508
                    {
 
509
                        //set a not existing error
 
510
                        res->add_Message(Visconte.Request.Message( ({ "", backtrace(),11, class_id->ref }) ));
 
511
                    }
 
512
                            
 
513
            };
 
514
            if(error)
 
515
                res->add_Message(Visconte.Request.Message(error));
 
516
                
 
517
                res->set_OWLContainer(assoc);
 
518
        
 
519
        return res;
 
520
    }   
 
521
    
 
522
 
 
523
/**
 
524
 * <p>Changes the id a OWLClass and all affected Inviduals and Properties
 
525
 * 
 
526
 * 
 
527
 * @param ID id - current id of the Class to rename 
 
528
 * @param new_id - the new id of the class
 
529
 * @param string comment - a comment for the ontology log
 
530
 * @return Result - the renamed class
 
531
 */
 
532
    public Visconte.Request.Result changeId(ID id, ID new_id, mapping label, string comment) 
 
533
    {     
 
534
            
 
535
        Visconte.Request.Result res = Visconte.Request.Result(); 
 
536
        Visconte.Onto.Item.OWLItem  new_class;
 
537
        Visconte.Onto.Item.OWLItem  old_class;
 
538
        
 
539
        array error=catch
 
540
        {
 
541
                    old_class = ontology->get_Item(id->ref);
 
542
                    if(old_class && !ontology->item_exists(new_id->ref))
 
543
                    {
 
544
                            //if one want to rename the class thing, just change the label
 
545
                            if(old_class->is_root())
 
546
                            {
 
547
                                    old_class->set_Label(label);
 
548
                                    ontology->update(old_class);
 
549
                            }
 
550
                            else
 
551
                            {
 
552
                                    string parent = old_class->get_parent()->get_Id();
 
553
                                    ID parent_id;
 
554
                                    if(!parent)
 
555
                                            parent_id=ID("Thing");
 
556
                                    else
 
557
                                            parent_id=ID(parent);
 
558
                                    new_class = factory->construct_Class(ontology,new_id,parent_id,label,({  }) ,({  }) );
 
559
                                    ontology->add_Item(new_class);
 
560
                                    new_class->mirror_restrictions();
 
561
                                    
 
562
                                    //change the individuals
 
563
                                     Visconte.Onto.OWLContainer inds = old_class->get_individuals();
 
564
                                     while(inds->has_items())
 
565
                                     {
 
566
                                             Visconte.Onto.Item.OWLIndividual ind = inds->next();
 
567
                                             ind->set_model_class(new_class);
 
568
                                             ontology->update(ind);
 
569
                                     }
 
570
                                     
 
571
                                      //change  all properties where the old class is the domain
 
572
                                     Visconte.Onto.OWLContainer domain_props = old_class->get_domain_properties();
 
573
                                     while(domain_props->has_items())
 
574
                                     {
 
575
                                             Visconte.Onto.Item.OWLProperty domain_prop = domain_props->next();
 
576
                                             domain_prop->set_domain(new_class);
 
577
                                             ontology->update(domain_prop);
 
578
                                     }
 
579
                                     
 
580
                                      //change all properties where the old class is the range
 
581
                                     Visconte.Onto.OWLContainer range_props = old_class->get_range_properties();
 
582
                                     while(range_props->has_items())
 
583
                                     {
 
584
                                             Visconte.Onto.Item.OWLProperty range_prop = range_props->next();
 
585
                                             range_prop->set_range(new_class);
 
586
                                             ontology->update(range_prop);
 
587
                                     }
 
588
                                     
 
589
                                      //change all direct subclasses
 
590
                                     Visconte.Onto.OWLContainer childs = old_class->get_childs();
 
591
                                     while(childs->has_items())
 
592
                                     {
 
593
                                             Visconte.Onto.Item.OWLClass child = childs->next();
 
594
                                             child->set_parent(new_class);
 
595
                                             ontology->update(child);
 
596
                                     }
 
597
                                     
 
598
                                     //finally remove the old class
 
599
                                     ontology->remove(old_class);
 
600
                            }
 
601
                    } 
 
602
                    else
 
603
                        //set a not existing error
 
604
                        res->add_Message(Visconte.Request.Message( ({ "", backtrace(),11, id->ref }) ));
 
605
        };
 
606
        
 
607
        if(error)
 
608
                res->add_Message(Visconte.Request.Message(error));
 
609
        else
 
610
                ontology->add_annotation(new_class,"class_id_changed",(string)comment, old_class->get_Label());
 
611
        
 
612
        res->set_OWLItem(new_class);
 
613
        return res;
 
614
    } 
 
615
/**
 
616
 * <p>Set Restrictions to a class - has currently no effect</p>
 
617
 * 
 
618
 * 
 
619
 * 
 
620
 * @param id 
 
621
 * @param new_id 
 
622
 * @param string comment - a comment for the ontology log
 
623
 * @return 
 
624
 */
 
625
    public Visconte.Request.Result set_restrictions(ID id, array equivalent, array different, int remove, string comment) 
 
626
    {        
 
627
         Visconte.Request.Result res = Visconte.Request.Result();
 
628
         Visconte.Onto.Item.OWLClass class_to_restrict;
 
629
         array error = catch{
 
630
                 
 
631
                 if(ontology->item_exists(id->ref))
 
632
                 {
 
633
                        class_to_restrict = ontology->get_Item(id->ref);
 
634
                        if(equivalent)
 
635
                        foreach( equivalent,ID cid)
 
636
                        {
 
637
                                
 
638
                                if(ontology->item_exists(cid->ref))
 
639
                                        if(remove)
 
640
                                                class_to_restrict->unset_equivalent_class(cid->ref);
 
641
                                        else
 
642
                                                class_to_restrict->set_equivalent_class(cid->ref);
 
643
                        }
 
644
                        
 
645
                        if(different)
 
646
                        foreach( different,ID cid)
 
647
                        {
 
648
                                
 
649
                                if(ontology->item_exists(cid->ref))
 
650
                                        if(remove)
 
651
                                                class_to_restrict->unset_different_from_class(cid->ref);
 
652
                                        else
 
653
                                                class_to_restrict->set_different_from_class(cid->ref);
 
654
                        }
 
655
                        
 
656
                        if(!different && !equivalent && remove)
 
657
                        {
 
658
                                class_to_restrict->unset_restrictions();
 
659
                        }
 
660
                        
 
661
                        
 
662
                        
 
663
                        ontology->update(class_to_restrict);
 
664
                 }
 
665
                 else
 
666
                        //set a not existing error
 
667
                        res->add_Message(Visconte.Request.Message( ({ "", backtrace(),11, id->ref }) ));
 
668
 
 
669
         };
 
670
         
 
671
         res->set_OWLItem(class_to_restrict);
 
672
         if(error)
 
673
                 res->add_Message(Visconte.Request.Message(error));
 
674
         else
 
675
                 ontology->add_annotation(class_to_restrict,"class_restricted",(string)comment, 0);
 
676
         
 
677
         return res;
 
678
                
 
679
    } 
 
680
    
 
681
    
 
682
 
 
683
} //}}}
 
684
 
 
685
 
 
686
 
 
687
 
 
688
/**
 
689
 * <p>class IndividualAction - Represents Actions on individuals in an ontology</p>
 
690
 */
 
691
class IndividualAction
 
692
{
 
693
//{{{ 
 
694
    inherit GenericAction;
 
695
 
 
696
 
 
697
/**
 
698
 * <p>Adds an Individual to the ontology</p>
 
699
 * 
 
700
 * @param ID individual_id - the id of the individual 
 
701
 * @param ID class_id - the id of the model class 
 
702
 * @param MVList properties - MultiValue List for the inserted properties
 
703
 * @param mapping same_as - no effect up to now, pass empty mapping 
 
704
 * @param different_from - no effect up to now, pass empty mapping 
 
705
 * @param string comment - a comment for the ontology log
 
706
 * @return Result - the new individual (if already exists, the current will be returned!)
 
707
 */
 
708
    public Visconte.Request.Result add(ID individual_id, ID class_id, mapping label, Visconte.MVList property_values, mapping same_as, mapping different_from , string comment) 
 
709
    {        
 
710
        Visconte.Request.Result res = Visconte.Request.Result();
 
711
        Visconte.Onto.Item.OWLIndividual new_individual;
 
712
        
 
713
        array error =catch
 
714
        {
 
715
                new_individual = factory->construct_Individual(ontology, individual_id, class_id, label,property_values);
 
716
 
 
717
                if(new_individual)
 
718
                {
 
719
                        ontology->add_Item(new_individual);
 
720
                }
 
721
                else
 
722
                        res->add_Message(Visconte.Request.Message( ({ "", backtrace(),11, individual_id->ref }) )); 
 
723
        };
 
724
        
 
725
        if(error)
 
726
                res->add_Message(Visconte.Request.Message(error));
 
727
        else
 
728
                ontology->add_annotation(new_individual,"individual_added",(string)comment,0);
 
729
        
 
730
        res->set_OWLItem(new_individual);
 
731
        
 
732
        return res;
 
733
    } 
 
734
/**
 
735
 * <p>Adds an Individual to the ontology which is from type document term</p>
 
736
 * 
 
737
 * @param ID individual_id - the id of the individual 
 
738
 * @param ID class_id - the id of the model class 
 
739
 * @param MVList properties - MultiValue List for the inserted properties
 
740
 * @param mapping same_as - no effect up to now, pass empty mapping 
 
741
 * @param different_from - no effect up to now, pass empty mapping 
 
742
 * @param string comment - a comment for the ontology log
 
743
 * @return Result - the new individual (if already exists, the current will be returned!)
 
744
 */
 
745
    public Visconte.Request.Result add_document_individual(ID individual_id, ID class_id, mapping label, Visconte.MVList property_values, mapping same_as, mapping different_from , string comment, string objectID, string mimeType) 
 
746
    {        
 
747
        Visconte.Request.Result res = Visconte.Request.Result();
 
748
        Visconte.Onto.Item.OWLIndividual new_individual;
 
749
        
 
750
        array error =catch
 
751
        {
 
752
                new_individual = factory->construct_Individual(ontology, individual_id, class_id, label,property_values);
 
753
                
 
754
                if(new_individual)
 
755
                {
 
756
                        ontology->add_Item(new_individual);
 
757
                        if(new_individual->get_model_class()->is_document_term())
 
758
                        ontology->set_document_term_properties(new_individual,objectID,mimeType);
 
759
                }
 
760
                else
 
761
                        res->add_Message(Visconte.Request.Message( ({ "", backtrace(),11, individual_id->ref }) )); 
 
762
        };
 
763
        
 
764
        if(error)
 
765
                res->add_Message(Visconte.Request.Message(error));
 
766
        else
 
767
                ontology->add_annotation(new_individual,"individual_added",(string)comment,0);
 
768
        
 
769
        res->set_OWLItem(new_individual);
 
770
        
 
771
        return res;
 
772
    } 
 
773
    
 
774
/**
 
775
 * <p>Deletes an individual from the ontology.</p>
 
776
 * 
 
777
 * @param ID id the id of the individual to delete
 
778
 * @param string comment - a comment for the ontology log
 
779
 * @return Result
 
780
 */
 
781
    public Visconte.Request.Result delete(ID id, string comment) 
 
782
    {        
 
783
            Visconte.Request.Result res = Visconte.Request.Result();
 
784
            Visconte.Onto.Item.OWLItem individual_to_delete;
 
785
            string individual_label;
 
786
            array error = catch
 
787
            {
 
788
                    if(ontology->item_exists(id->ref))
 
789
                    {
 
790
                             individual_to_delete = ontology->get_Item(id->ref);
 
791
                             individual_label=individual_to_delete->get_Label();
 
792
                             Visconte.Onto.Item.OWLClass class_ = ontology->get_Item("#Thing");
 
793
                             Visconte.Onto.OWLContainer all_inds = class_->get_individuals_down_to_leaf();
 
794
                             all_inds->reset_iterator();
 
795
                             while(all_inds->has_items())
 
796
                             { 
 
797
                                     Visconte.Onto.Item.OWLIndividual ind = all_inds->next();
 
798
                                     if(ind->is_associated_with(individual_to_delete))
 
799
                                     ind->remove_associations_with(individual_to_delete);
 
800
                                     ontology->update(ind);
 
801
                             }
 
802
                            ontology->remove(individual_to_delete);
 
803
                    }
 
804
                    else
 
805
                            res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, id->ref }) ));
 
806
            };
 
807
            
 
808
            if(error)
 
809
                res->add_Message(Visconte.Request.Message(error));
 
810
            else
 
811
                ontology->add_annotation(individual_to_delete,"individual_deleted",(string)comment,0);
 
812
            res->set_OWLItem(individual_to_delete);
 
813
            
 
814
            return res;
 
815
    } 
 
816
 
 
817
 
 
818
 
 
819
/**
 
820
 * <p>Updates an Individual</p>
 
821
 * Give a new MVList to update a given Individual
 
822
 * 
 
823
 * @param id - the id of the Indvidual
 
824
 * @param properties -  the properties
 
825
 * @param  comment - a comment for the ontology log
 
826
 * @return Result - the changed Individual
 
827
 */
 
828
    public Visconte.Request.Result update(ID id,  MVList properties, mapping label, string comment) 
 
829
    {        
 
830
              Visconte.Request.Result res = Visconte.Request.Result();
 
831
              Visconte.Onto.Item.OWLIndividual individual_to_update;
 
832
              array error = catch
 
833
              {
 
834
                    if(ontology->item_exists(id->ref))
 
835
                    {
 
836
                            individual_to_update = ontology->get_Item(id->ref);
 
837
                            individual_to_update->set_Label(label);
 
838
                            individual_to_update->reset_properties();
 
839
                            individual_to_update->set_Properties(properties);
 
840
                            ontology->update(individual_to_update);
 
841
                    }
 
842
                    else
 
843
                            res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, id->ref }) ));
 
844
              };
 
845
            
 
846
            if(error)
 
847
                res->add_Message(Visconte.Request.Message(error));
 
848
            else
 
849
                ontology->add_annotation(individual_to_update,"individual_updated",(string)comment,0);
 
850
            res->set_OWLItem(individual_to_update);
 
851
            
 
852
            return res;
 
853
    } 
 
854
/**
 
855
 * <p>Updates an Individual</p>
 
856
 * Give a new MVList to update a given Individual
 
857
 * 
 
858
 * @param id - the id of the Indvidual
 
859
 * @param properties -  the properties
 
860
 * @param  comment - a comment for the ontology log
 
861
 * @return Result - the changed Individual
 
862
 */
 
863
    public Visconte.Request.Result update_document_individual(ID id,  MVList properties, mapping label, string comment, string objectID, string mimetype) 
 
864
    {        
 
865
              Visconte.Request.Result res = Visconte.Request.Result();
 
866
              Visconte.Onto.Item.OWLIndividual individual_to_update;
 
867
              array error = catch
 
868
              {
 
869
                    if(ontology->item_exists(id->ref))
 
870
                    {
 
871
                            individual_to_update = ontology->get_Item(id->ref);
 
872
                            individual_to_update->set_Label(label);
 
873
                            individual_to_update->reset_properties();
 
874
                            individual_to_update->set_Properties(properties);
 
875
                           
 
876
                            ontology->update(individual_to_update);
 
877
                            if(individual_to_update->get_model_class()->is_document_term())
 
878
                            ontology->set_document_term_properties(individual_to_update,objectID,mimetype);
 
879
                    }
 
880
                    else
 
881
                            res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, id->ref }) ));
 
882
              };
 
883
            
 
884
            if(error)
 
885
                res->add_Message(Visconte.Request.Message(error));
 
886
            else
 
887
                ontology->add_annotation(individual_to_update,"individual_updated",(string)comment,0);
 
888
            res->set_OWLItem(individual_to_update);
 
889
            
 
890
            return res;
 
891
    } 
 
892
/**
 
893
 
 
894
 */
 
895
    public Visconte.Request.Result change_Id(ID id, ID new_id, mapping label, string comment) 
 
896
    {
 
897
             Visconte.Request.Result res  = Visconte.Request.Result();
 
898
             Visconte.Onto.Item.OWLIndividual current_ind;
 
899
             Visconte.Onto.Item.OWLIndividual new_individual;
 
900
              array error = catch
 
901
              {
 
902
                    if(ontology->item_exists(id->ref) && !ontology->item_exists(new_id->ref))
 
903
                    {
 
904
                             current_ind = ontology->get_Item(id->ref);
 
905
                             ID model_class = ID(current_ind->get_model_class()->get_Id());
 
906
                             new_individual = factory->construct_Individual(ontology, new_id, model_class,label,current_ind->get_property_list());
 
907
                             ontology->add_Item(new_individual);
 
908
                             //change all interconnections
 
909
                             Visconte.Onto.Item.OWLClass class_ = ontology->get_Item("#Thing");
 
910
                             Visconte.Onto.OWLContainer all_inds = class_->get_individuals_down_to_leaf();
 
911
                             all_inds->reset_iterator();
 
912
                             while(all_inds->has_items())
 
913
                             { 
 
914
                                     Visconte.Onto.Item.OWLIndividual ind = all_inds->next();
 
915
                                     if(ind->is_associated_with(current_ind))
 
916
                                     ind->replace_individual(current_ind,new_individual);
 
917
                                     ontology->update(ind);
 
918
                             }
 
919
                             ontology->remove(current_ind);
 
920
                    }
 
921
                };
 
922
            if(error)
 
923
                res->add_Message(Visconte.Request.Message(error));
 
924
            else
 
925
                ontology->add_annotation(new_individual,"individual_id_changed",(string)comment,0);
 
926
            res->set_OWLItem(new_individual);
 
927
            
 
928
            return res;
 
929
    }    
 
930
/**
 
931
 * <p>Retrieve all Individuals wich have a connection/association to and from  the current one </p>
 
932
 * 
 
933
 * 
 
934
 * @param ID  id - the id of the individual to retrive the references from
 
935
 * @param int no_back_refs - if set, no incoming assocaitions will be returned
 
936
 * @param int include_self - if set, the given individual will be included to Result 
 
937
 * @return Result - Referenced Individuals
 
938
 */
 
939
    public Visconte.Request.Result get_all_references(ID indivual_id,int no_back_refs, int include_self) 
 
940
    {        
 
941
           Visconte.Request.Result res = Visconte.Request.Result();
 
942
           Visconte.Onto.OWLContainer references =  Visconte.Onto.OWLContainer();
 
943
          
 
944
           array error = catch{
 
945
                   if(!no_back_refs)
 
946
                   {
 
947
                           //start at the root
 
948
                           Visconte.Onto.Item.OWLClass class_ = ontology->get_Item("#Thing");
 
949
                           Visconte.Onto.OWLContainer all_inds = class_->get_individuals_down_to_leaf();
 
950
                           all_inds->reset_iterator();
 
951
                           while(all_inds->has_items())
 
952
                           { 
 
953
                                    Visconte.Onto.Item.OWLIndividual ind = all_inds->next();
 
954
                                    if(ind->is_associated_with(indivual_id->ref))
 
955
                                            references->add(ind);
 
956
                           }
 
957
                   }
 
958
                   Visconte.Onto.Item.OWLIndividual ind = ontology->get_Item(indivual_id->ref);
 
959
                   references->merge(ind->get_associations());
 
960
                   if(include_self)
 
961
                        references->add(ind);   
 
962
            };
 
963
            
 
964
            if(error)
 
965
                res->add_Message(Visconte.Request.Message(error));
 
966
           
 
967
            res->set_OWLContainer(references);
 
968
        
 
969
        return res;
 
970
    }
 
971
    
 
972
    
 
973
/**
 
974
 * <p>Retrieve all Individuals wich have a connection/association to and from  the current one </p>
 
975
 * 
 
976
 * 
 
977
 * @param ID  id - the id of the individual to retrive the references from
 
978
 * @param int no_back_refs - if set, no incoming assocaitions will be returned
 
979
 * @param int include_self - if set, the given individual will be included to Result 
 
980
 * @return Result - Referenced Individuals
 
981
 */
 
982
    public string get_individual_id(string steamObjectid) 
 
983
    {        
 
984
           Visconte.Request.Result res = Visconte.Request.Result();
 
985
           Visconte.Onto.OWLContainer references =  Visconte.Onto.OWLContainer();
 
986
           string result="none";
 
987
           array error = catch{
 
988
                  
 
989
                           //start at the root
 
990
                           Visconte.Onto.Item.OWLClass class_ = ontology->get_Item("#Thing");
 
991
                           Visconte.Onto.OWLContainer all_inds = class_->get_individuals_down_to_leaf();
 
992
                           all_inds->reset_iterator();
 
993
                           while(all_inds->has_items())
 
994
                           { 
 
995
                                    Visconte.Onto.Item.OWLIndividual ind = all_inds->next();
 
996
                                    mapping steam_properties = ind->get_steam_properties();
 
997
                                    // result+=(string)steam_properties->objectid+"-->"+steamObjectid+"::";
 
998
                                    string id = (string)steam_properties->objectid+"";
 
999
                                    if(steamObjectid+"" == steam_properties->objectid+"")
 
1000
                                    {
 
1001
                                            string id = (string)ind->get_Id();
 
1002
                                            return id[1..]; 
 
1003
                                           
 
1004
                                    }
 
1005
                           }
 
1006
                   
 
1007
                 
 
1008
            };
 
1009
            
 
1010
           return result;
 
1011
    }
 
1012
 
1013
 
 
1014
/**
 
1015
 * <p>class PropertyAction - Property related actions</p>
 
1016
 */
 
1017
class PropertyAction
 
1018
//{{{ 
 
1019
{
 
1020
 
 
1021
inherit GenericAction;
 
1022
 
 
1023
 
 
1024
 
 
1025
/**
 
1026
 * <p>add a property to the ontology</p>
 
1027
 * TODO: Add cardinality
 
1028
 * @param id the new id of the property
 
1029
 * @param mapping label - the labels of the property (currently only english) (["en":"Your Label"]) 
 
1030
 * @param ID domain - the id of the domain (source) 
 
1031
 * @param ID range - the id of the range (target)
 
1032
 * @param mapping restrictions - symetric, transitive etc. (has currently no effect in the ontology)
 
1033
 * @param string  comment - a comment for the ontology log
 
1034
 * @return Result - the  new Property (if already exists, the current one will be returned) 
 
1035
 */
 
1036
    public Visconte.Request.Result add(ID id, mapping label, mapping restrictions, ID domain, ID range, string comment) 
 
1037
    {  
 
1038
            
 
1039
        Visconte.Request.Result res = Visconte.Request.Result();
 
1040
        Visconte.Onto.Item.OWLProperty property;
 
1041
        array error =catch
 
1042
        {
 
1043
                property = factory->construct_Property(ontology,id,label,restrictions,domain,range);
 
1044
                ontology->add_Item(property);
 
1045
                if(property->ITEMTYPE==Visconte.Onto.Item.OWLItem.OBJECT_PROPERTY)
 
1046
                        ontology->add_annotation(property,"add_association", comment,domain->ref);
 
1047
                else
 
1048
                        ontology->add_annotation(property,"add_property", comment,domain->ref);
 
1049
                        
 
1050
        };
 
1051
        
 
1052
        if(error)
 
1053
                res->add_Message(Visconte.Request.Message(error));
 
1054
        
 
1055
        
 
1056
        res->set_OWLItem(property);
 
1057
        
 
1058
        return res;
 
1059
    } 
 
1060
 
 
1061
/**
 
1062
 * <p>Delete a Property from the ontology</p>
 
1063
 * 
 
1064
 * @param ID id - the id of the property
 
1065
 * @param string  comment - a comment for the ontology log
 
1066
 * @return Result
 
1067
 */
 
1068
    public Visconte.Request.Result delete(ID id, string comment) 
 
1069
    {        
 
1070
       Visconte.Request.Result res = Visconte.Request.Result();
 
1071
       Visconte.Onto.Item.OWLProperty prop;
 
1072
       
 
1073
       array error=catch
 
1074
       {
 
1075
       
 
1076
               if(ontology->item_exists(id->ref))
 
1077
               {
 
1078
                  
 
1079
                       prop =  ontology->get_Item(id->ref);
 
1080
                       //get the class id of the domain
 
1081
                       Visconte.Onto.OWLContainer container= prop->get_domain()->get_individuals_down_to_leaf();
 
1082
                       //update the Individuals which hold this property, by removing it
 
1083
                       while(container->has_items())
 
1084
                       {
 
1085
                               Visconte.Onto.Item.OWLIndividual i = container->next();
 
1086
                               i->remove_Property(prop);
 
1087
                               ontology->update(i);
 
1088
                       }
 
1089
                       
 
1090
                       //remove the poperty
 
1091
                       ontology->remove(prop);
 
1092
               }
 
1093
               else
 
1094
                       res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, id->ref }) ));
 
1095
       };
 
1096
       if(error)
 
1097
               res->add_Message(Visconte.Request.Message(error));
 
1098
       else
 
1099
                ontology->add_annotation(prop,"property_deleted",(string)comment,0);
 
1100
       res->set_OWLItem(prop);
 
1101
       
 
1102
       return res;
 
1103
       
 
1104
    } 
 
1105
 
 
1106
    
 
1107
    
 
1108
    
 
1109
/**
 
1110
 * <p>Rename a Property</p>
 
1111
 * 
 
1112
 * @param ID id - the id of the property
 
1113
 * @param ID newId - the new Id of the property
 
1114
 * @param string  comment - a comment for the ontology log
 
1115
 * @return Result
 
1116
 */
 
1117
    public Visconte.Request.Result change_Id(ID id,ID new_id, mapping label, string comment) 
 
1118
    {        
 
1119
       Visconte.Request.Result res = Visconte.Request.Result();
 
1120
       Visconte.Onto.Item.OWLProperty prop_old;
 
1121
       Visconte.Onto.Item.OWLProperty prop_new;
 
1122
       
 
1123
       array error=catch
 
1124
       {
 
1125
       
 
1126
               if(ontology->item_exists(id->ref) && !ontology->item_exists(new_id->ref))
 
1127
               {
 
1128
                  
 
1129
                       prop_old =  ontology->get_Item(id->ref);
 
1130
                       ID domain = ID(prop_old->get_domain()->get_Id());
 
1131
                       ID range;
 
1132
                       if(prop_old->ITEMTYPE!=Visconte.Onto.Item.OWLItem.DATATYPE_PROPERTY)
 
1133
                               range = ID(prop_old->get_range()->get_Id());
 
1134
                       else
 
1135
                               range = ID("xsd:"+prop_old->get_range());
 
1136
                       prop_new = factory->construct_Property(ontology,new_id,label,([]),domain,range);
 
1137
                       ontology->add_Item(prop_new);
 
1138
                       Visconte.Onto.OWLContainer container= prop_old->get_domain()->get_individuals_down_to_leaf();
 
1139
                       //update the Individuals which hold this property, by replacing it
 
1140
                       while(container->has_items())
 
1141
                       {
 
1142
                               Visconte.Onto.Item.OWLIndividual i = container->next();
 
1143
                               i->replace_Property(prop_old,prop_new);
 
1144
                               ontology->update(i);
 
1145
                       }
 
1146
                       
 
1147
                       //remove the poperty
 
1148
                       ontology->remove(prop_old);
 
1149
               }
 
1150
               else
 
1151
                       res->add_Message(Visconte.Request.Message( ({ "", backtrace(), 11, id->ref }) ));
 
1152
       };
 
1153
       if(error)
 
1154
               res->add_Message(Visconte.Request.Message(error));
 
1155
       else
 
1156
                ontology->add_annotation(prop_new,"property_id_changed",(string)comment,0);
 
1157
       res->set_OWLItem(prop_new);
 
1158
       
 
1159
       return res;
 
1160
       
 
1161
    } 
 
1162
 
 
1163
 
 
1164
/**
 
1165
 * <p>Does ...</p>
 
1166
 * 
 
1167
 * 
 
1168
 * @param id 
 
1169
 * @param restrictions 
 
1170
 * @return 
 
1171
 */
 
1172
    public Visconte.Request.Result set_Restrictions(ID id, mapping restrictions, string comment) {        
 
1173
        // your code here
 
1174
        return 0;
 
1175
    } 
 
1176
}
 
1177
 
 
1178
 
 
1179
/**
 
1180
 * <p>class OntologyAction - Action Class for special retrievals on the whole ontology</p>
 
1181
 */
 
1182
class OntologyAction
 
1183
{
 
1184
//{{{ 
 
1185
inherit GenericAction;
 
1186
 
 
1187
/**
 
1188
 * <p>Returns a hierarchical map of class dependencies for the representation in the visconte ontology browser.
 
1189
 * An options mapping indicates which informations should be also insert in the map e.g Assocaitions Individuals etc</p>
 
1190
 * 
 
1191
 * 
 
1192
 * @param root_id the root id of the map (class id)
 
1193
 * @param options mappig with name value pairs
 
1194
 * @return 
 
1195
 */
 
1196
    public Visconte.Request.Result get_Class_List(ID model_class_id, int|void with_myself) 
 
1197
    {        
 
1198
       Visconte.Request.Result res = Visconte.Request.Result();
 
1199
       Visconte.Onto.OWLContainer all_child_container;
 
1200
       Visconte.Onto.Item.OWLClass model;
 
1201
       array error = catch
 
1202
       {
 
1203
                model = ontology->get_Item(model_class_id->ref);
 
1204
                all_child_container=model->get_all_childs();
 
1205
                if(with_myself)
 
1206
                        all_child_container->add(model);
 
1207
       };
 
1208
       if(error)
 
1209
            res->add_Message(Visconte.Request.Message(error));
 
1210
               
 
1211
       res->set_OWLContainer(all_child_container);
 
1212
       
 
1213
       return res;
 
1214
    } 
 
1215
 
 
1216
 
 
1217
/**
 
1218
 * <p>Returns a hierarchical map of class dependencies for the representation in the visconte ontology browser.
 
1219
 * An options mapping indicates which informations should be also insert in the map e.g Assocaitions Individuals etc</p>
 
1220
 * 
 
1221
 * 
 
1222
 * @param root_id the root id of the map (class id)
 
1223
 * @param options mappig with name value pairs
 
1224
 * @return 
 
1225
 */
 
1226
    public Visconte.Request.Result get_Hierarchical_Map() 
 
1227
    {        
 
1228
       Visconte.Request.Result res = Visconte.Request.Result();
 
1229
       Visconte.Onto.Item.OWLClass root;
 
1230
       array error = catch
 
1231
       {
 
1232
                root = ontology->get_Item("#Thing");
 
1233
       };
 
1234
       
 
1235
       if(error)
 
1236
                res->add_Message(Visconte.Request.Message(error));
 
1237
       res->set_OWLItem(root,Visconte.Request.Result.RENDER_DEEP);
 
1238
       
 
1239
       return res;
 
1240
    } 
 
1241
 
 
1242
 
 
1243
/**
 
1244
 * <p>Returns a hierarchical map of class dependencies for the representation in the visconte ontology browser.
 
1245
 * An options mapping indicates which informations should be also insert in the map e.g Assocaitions Individuals etc</p>
 
1246
 * 
 
1247
 * 
 
1248
 * @param root_id the root id of the map (class id)
 
1249
 * @param options mappig with name value pairs
 
1250
 * @return 
 
1251
 */
 
1252
    public Visconte.Request.Result get_Up_Map(ID model_class_id) 
 
1253
    {        
 
1254
       Visconte.Request.Result res = Visconte.Request.Result();
 
1255
       Visconte.Onto.Item.OWLClass klass;
 
1256
       array error = catch
 
1257
       {
 
1258
                klass=ontology->get_Class(model_class_id->ref);
 
1259
       };
 
1260
       
 
1261
       if(error)
 
1262
                res->add_Message(Visconte.Request.Message(error));
 
1263
       res->set_OWLItem(klass,Visconte.Request.Result.RENDER_UP);
 
1264
       
 
1265
       return res;
 
1266
    }
 
1267
 
 
1268
/**
 
1269
 * <p>Get a cluster of individuals which fit to the constrains in the statements mapping.</p>
 
1270
 * 
 
1271
 * 
 
1272
 * @param statements mapping with matching attributes 
 
1273
 * @return 
 
1274
 */
 
1275
    public Visconte.Request.Result get_Individuals_by_Class(ID model_class_id, int edge_restriction) 
 
1276
    {        
 
1277
        Visconte.Request.Result res = Visconte.Request.Result(); 
 
1278
        Visconte.Onto.OWLContainer individuals_container;
 
1279
        array error = catch
 
1280
        {
 
1281
                Visconte.Onto.Item.OWLClass model_class = ontology->get_Item(model_class_id->ref);
 
1282
                write(model_class->get_Id());
 
1283
                switch(edge_restriction)
 
1284
                {
 
1285
                        
 
1286
                        case 0 :
 
1287
                                individuals_container = model_class->get_all_individuals();
 
1288
                                break;
 
1289
                        case 1 :
 
1290
                                individuals_container = model_class->get_individuals_up_to_root();
 
1291
                                break;
 
1292
                        case 2 :
 
1293
                                individuals_container = model_class->get_individuals_down_to_leaf();
 
1294
                                break;
 
1295
                                
 
1296
                        default:       
 
1297
                                individuals_container = model_class->get_all_individuals();
 
1298
                                break;
 
1299
                }
 
1300
        };
 
1301
        
 
1302
        if(error)
 
1303
                res->add_Message(Visconte.Request.Message(error));
 
1304
        else
 
1305
                res->set_OWLContainer(individuals_container);
 
1306
        
 
1307
        return res;
 
1308
    }
 
1309
                
 
1310
        
 
1311
        
 
1312
/**
 
1313
 * <p>Get the annotations of an ontology</p>
 
1314
 * 
 
1315
 * 
 
1316
 * @return string xml;
 
1317
 */
 
1318
    public string get_annotations() 
 
1319
    { 
 
1320
            return ontology->get_annotations();
 
1321
    } 
 
1322
 
 
1323
/**
 
1324
 * <p>Get the Parser.XML.Tree.Node of the ontology annotations</p>
 
1325
 * 
 
1326
 * 
 
1327
 * @return string xml;
 
1328
 */
 
1329
    public Parser.XML.Tree.Node get_annotation_node() 
 
1330
    { 
 
1331
            return ontology->ontology_log;
 
1332
    }
 
1333
/**
 
1334
 * <p>Retrieves Metainformations about the ontology</p>
 
1335
 * 
 
1336
 * 
 
1337
 * @return int version number
 
1338
 */
 
1339
    public int get_version() {        
 
1340
        
 
1341
        return ontology->get_version();
 
1342
    } 
 
1343
    
 
1344
/**
 
1345
 * <p>Sets a comment for specified object</p>
 
1346
 * 
 
1347
 * 
 
1348
 * @param id the id, the comment should linked with
 
1349
 * @param author the author of the comment
 
1350
 * @param msg the message
 
1351
 * @return 
 
1352
 */
 
1353
    public int set_Comment(ID id,string comment) {        
 
1354
        
 
1355
                Visconte.Onto.Item.OWLItem i = ontology->get_Item(id->ref);
 
1356
                if(i)
 
1357
                {
 
1358
                        ontology->add_annotation(i,"comment_added",(string)comment,0);
 
1359
                        return 1;
 
1360
                }
 
1361
                else
 
1362
                        return 0;
 
1363
                        
 
1364
    } 
 
1365
    
 
1366
    
 
1367
 
 
1368
 
1369
 
 
1370
 
 
1371
 
 
1372
 
 
1373