~ubuntu-branches/ubuntu/wily/steam/wily

« back to all changes in this revision

Viewing changes to server/libraries/Visconte.pmod/Onto.pmod/Item.pmod

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// import Visconte.Onto;
2
 
// import Visconte;
3
 
 
4
 
 
5
 
class OWLItem
6
 
//{{{ 
7
 
{
8
 
/**
9
 
 * <p>class OWLItem - Represents an abstract OWL Item. this class shouldnt be instantiated not directly. Use one of the Subclasses instead
10
 
 * with dynamic binding OWLItem x = OWLClass(....), you can bind the this class in your code
11
 
 *
12
 
 * Construction of all subclasses OWLItems:
13
 
 *              For a construction of a new Item use the OWLItemFactory Class - it checks the data for consitence
14
 
 *              For retrieval use the get_item methods in class ontology, which will return valid and existing items
15
 
 *
16
 
 * Changes to Items:
17
 
 *              If you change any property in an item it will not directly be saved to the ontology. If you want to commit your changes
18
 
 *              use the method update(OWLItem) in class ontology e.g. from the ActionClass with ontology->update(YourItem)
19
 
 *
20
 
 * Not functional by now:
21
 
 *              The euqivalent and different_from restrictions on a class are implementend it this datatstructure, but not in the ontology class.
22
 
 *              The restrictions of properties e.g. symetric etc. are also functional here, but not in the ontology class
23
 
 *              Working with this elements will (up to now) not be represented in the ontology
24
 
 * </p>
25
 
 */
26
 
 
27
 
 
28
 
    
29
 
    
30
 
/**
31
 
 * <p>Represents the type of the item, with the constants listed below,
32
 
 * subclasses have to replace this type</p>
33
 
 */
34
 
    public constant ITEMTYPE = 0;
35
 
 
36
 
/**
37
 
 * <p>Represents a Class</p>
38
 
 */
39
 
    public constant CLASS = 1;
40
 
 
41
 
/**
42
 
 * <p>Represents an Individual</p>
43
 
 */
44
 
    public constant  INDIVIDUAL = 2;
45
 
 
46
 
/**
47
 
 * <p>Represents an Oject Property</p>
48
 
 */
49
 
    public constant  OBJECT_PROPERTY = 3;
50
 
 
51
 
/**
52
 
 * <p>Represents Datatype Property</p>
53
 
 */
54
 
    public constant  DATATYPE_PROPERTY = 4;
55
 
 
56
 
/**
57
 
 * <p>Represents the unique id of the item
58
 
 * to ensure this id is really unique, items should 
59
 
 * be constructed with OWLItemFactory</p>
60
 
 */
61
 
    static string id;
62
 
 
63
 
/**
64
 
 * <p>Represents the ontology, this 
65
 
 * variable will be init in the subclasses</p>
66
 
 */
67
 
    static Visconte.Onto.Ontology ontology;
68
 
    
69
 
/**
70
 
 * <p>Represents the labels with the 
71
 
 * connected language flag, e.g en fr de etc.
72
 
 * ["en"]:["my label"]</p>
73
 
 */
74
 
    static mapping(string:string) label =(["en":""]);
75
 
    
76
 
 
77
 
/**
78
 
 * <p>Returns the date of last change in unixtime</p>
79
 
 * 
80
 
 * 
81
 
 * @return string timestamp
82
 
 */
83
 
    public string get_date_of_change() {        
84
 
       return ontology->get_meta(this_object())["lastChanged"];
85
 
    } 
86
 
 
87
 
/**
88
 
 * <p>Returns the author last edited the item</p>
89
 
 * 
90
 
 * 
91
 
 * @return string name of author
92
 
 */
93
 
    public string get_last_author() {        
94
 
       return ontology->get_meta(this_object())["author"];
95
 
    } 
96
 
    
97
 
    
98
 
/**
99
 
 * <p>Returns the id of the Item</p>
100
 
 * 
101
 
 * 
102
 
 * @return string id
103
 
 */
104
 
    public string get_Id() {        
105
 
        
106
 
        return id;
107
 
    } 
108
 
 
109
 
    
110
 
    
111
 
/**
112
 
 * <p>Test for inequality</p>
113
 
 * 
114
 
 * 
115
 
 * @return int 0|1
116
 
 */
117
 
    public int `!=(OWLItem item) {        
118
 
        
119
 
       return !is_equal(item);
120
 
    } 
121
 
 
122
 
    
123
 
    
124
 
/**
125
 
 * <p>Test for equality by id comapring the id's</p>
126
 
 * 
127
 
 * 
128
 
 * @return 
129
 
 */
130
 
    public int is_equal(OWLItem item) {        
131
 
        
132
 
       return(this_program::id==item->get_Id());
133
 
    } 
134
 
 
135
 
 
136
 
/**
137
 
 * <p>Sets a label for the desired language</p>
138
 
 * the mapping is structured as language code (ed,de,etc...) and label
139
 
 * currently only english is supported!
140
 
 * 
141
 
 * @param mapping label the label
142
 
 */
143
 
    public void set_Label(mapping label) 
144
 
    { 
145
 
        //set the label to the language
146
 
        if(label)
147
 
                this_program::label=label;
148
 
        
149
 
        
150
 
    } 
151
 
 
152
 
/**
153
 
 * <p>Get the label for the desired language</p>
154
 
 * currently en is the only supported language code
155
 
 * 
156
 
 * @param string lang - the language code (en,de etc..) 
157
 
 * @return 
158
 
 */
159
 
    public string get_Label(string|void lang) 
160
 
    {  
161
 
            string item_label="";
162
 
            if(lang)
163
 
            {
164
 
                    item_label = label[lang];
165
 
            }
166
 
            else
167
 
            {    
168
 
                    item_label = label["en"]; 
169
 
            }
170
 
            
171
 
                 
172
 
                 
173
 
            return item_label;
174
 
    } 
175
 
 
176
 
} //}}}
177
 
 
178
 
/**   
179
 
*
180
 
* <p>Class OWLClass
181
 
* Represents an OWL Class Element and provides different properties and connections to other items</p>
182
 
* see Comment Header in OWLItem for more details!
183
 
*
184
 
*
185
 
*/
186
 
class OWLClass
187
 
//{{{ 
188
 
{
189
 
inherit OWLItem;
190
 
 
191
 
 
192
 
 
193
 
 
194
 
/**
195
 
 * <p>Represents the type of the item, which is CLASS here</p>
196
 
 */
197
 
    public constant ITEMTYPE = CLASS;   
198
 
        
199
 
/**
200
 
 * <p>Represents the id of the parent class</p>
201
 
 */
202
 
    public mixed parent_id;
203
 
 
204
 
/**
205
 
 * <p>Represents the ids of the direct childs</p>
206
 
 */
207
 
    private array childs ;
208
 
/**
209
 
 * <p>Represents  the connected individuals</p>
210
 
 */
211
 
    private array individuals ;
212
 
    
213
 
/**
214
 
 * <p>Represents the connected properties whrer this class is the domain object</p>
215
 
 */
216
 
    private  array domain_properties ;
217
 
    
218
 
/**
219
 
 * <p>Represents the connected properties where this class is the range object</p>
220
 
 */
221
 
    private  array range_properties ;
222
 
    
223
 
/**
224
 
 * <p>contains all class which are set equal to this one</p>
225
 
 */
226
 
    private array equivalent_Class=({});
227
 
    
228
 
    
229
 
/**
230
 
 * <p>Contains all class which are set different from this</p>
231
 
 */
232
 
    private array different_From=({});;
233
 
 
234
 
    
235
 
/**
236
 
* <p>Construct a Class</p>
237
 
238
 
239
 
* @param ontology - the ontology object operating on
240
 
* @param id - the id of the class 
241
 
* @param mixed parent_id - class id this is subclass of
242
 
*        (either int 0, which will be a subclass of Thing, or the id as string)
243
 
* @param mapping label - the label mapping (e.g. (["en":"Iam the label"])
244
 
* @param array domain_properties - array with the ids of the Object- and DataProperties this class acts as domain in
245
 
* @param array range_properties - array with the ids of the ObjectProperties this class acts as range in
246
 
* @param array childs - array with the ids of the subclasses
247
 
* @param array individuals - array with the ids of the individuals which where templated from this class (not inherited!)
248
 
* @param array equivalent_Class - array with the ids of the equivalent classes
249
 
* @param array different_From - array with the ids of the different classes which are different from
250
 
 
251
 
*/
252
 
    public void create(Visconte.Onto.Ontology ontology, string id, mixed parent_id, mapping label,
253
 
    array domain_properties, array range_properties, array childs, array individuals, array equivalent_Class, array different_From) 
254
 
    {        
255
 
        
256
 
        this_program::id=id;
257
 
        
258
 
        if(parent_id==0)
259
 
                this_program::parent_id="#Thing";
260
 
        else
261
 
                this_program::parent_id=parent_id;
262
 
        this_program::ontology=ontology;
263
 
        if(label)
264
 
                this_program::label=label;
265
 
        this_program::domain_properties = domain_properties;
266
 
        this_program::childs = childs;
267
 
        this_program::individuals=individuals;
268
 
        this_program::range_properties=range_properties;
269
 
        this_program::equivalent_Class=equivalent_Class;
270
 
        this_program::different_From=different_From;
271
 
    } 
272
 
 
273
 
 
274
 
/**
275
 
 * <p>Is this class a document term</p>
276
 
 * 
277
 
 * 
278
 
 * @return boolean
279
 
 */
280
 
    public int is_document_term()
281
 
    {
282
 
            int isDocumentTerm = 0;
283
 
            if(ontology->is_document_term(this_object()))
284
 
                    isDocumentTerm=1;
285
 
            else
286
 
            {
287
 
                    object owl_class = this_object();
288
 
                    while(owl_class->has_parent())
289
 
                    {
290
 
                            owl_class=owl_class->get_parent();
291
 
                            if(ontology->is_document_term(owl_class))
292
 
                            {   
293
 
                                    
294
 
                                    isDocumentTerm=1;
295
 
                                    break;
296
 
                            }
297
 
                                  
298
 
                    }     
299
 
            }
300
 
            return isDocumentTerm;   
301
 
    }
302
 
/**
303
 
 * <p>This Method adds the equivalenClass and differentFrom to the 
304
 
 *    associated classes </p>
305
 
 * 
306
 
 * 
307
 
 * @return 
308
 
 */
309
 
    public void mirror_restrictions()
310
 
    {
311
 
            //if myself exists in the ontology
312
 
            if(ontology->item_exists(this_program::id))
313
 
            {
314
 
                        foreach (equivalent_Class, string class_id)
315
 
                        {
316
 
                                equivalent_Class-=({class_id});
317
 
                                set_equivalent_class(class_id);
318
 
                        }
319
 
                        foreach (different_From, string class_id)
320
 
                        {
321
 
                                different_From-=({class_id});
322
 
                                set_different_from_class(class_id);
323
 
                        }
324
 
            }
325
 
    }
326
 
 
327
 
    
328
 
/**
329
 
 * <p>Get the Properties where this class acts as range</p>
330
 
 * 
331
 
 * 
332
 
 * @return Visconte.Onto.OWLContainer - filled with OWLProperties
333
 
 */
334
 
    public Visconte.Onto.OWLContainer get_range_properties() 
335
 
    {        
336
 
       return ontology->get_Items(range_properties);
337
 
    } 
338
 
    
339
 
    
340
 
    
341
 
/**
342
 
 * <p>Get the Properties where this class acts as domain</p>
343
 
 * 
344
 
 * 
345
 
 * @return Visconte.Onto.OWLContainer - filled with OWLProperties
346
 
 */
347
 
    public Visconte.Onto.OWLContainer get_domain_properties() 
348
 
    {        
349
 
       return ontology->get_Items(domain_properties);
350
 
    } 
351
 
 
352
 
 
353
 
 /**
354
 
 * <p>Returns all Domain properties of this class (inherited and self)</p>
355
 
 * 
356
 
 * 
357
 
 * @return Visconte.Onto.OWLContainer - filled with OWLProperties
358
 
 */
359
 
    public Visconte.Onto.OWLContainer get_inherited_domain_properties() 
360
 
    {        
361
 
     
362
 
       
363
 
        Visconte.Onto.OWLContainer domains = get_domain_properties() ;
364
 
           if(has_parent())
365
 
           {
366
 
                 OWLClass parent  = get_parent();
367
 
                 
368
 
                 domains->merge(parent->get_inherited_domain_properties());
369
 
                   
370
 
           }
371
 
          return domains;
372
 
    } 
373
 
    
374
 
/**
375
 
 * <p>Returns an array whith the domain ids (only self) </p>
376
 
 * 
377
 
 * 
378
 
 * @return array(string) -- ids
379
 
 */
380
 
    public array get_property_ids() 
381
 
    {        
382
 
       return domain_properties;
383
 
    } 
384
 
    
385
 
    
386
 
    
387
 
/**
388
 
 * <p>Returns the classes which are equivalent to this</p>
389
 
 * 
390
 
 * 
391
 
 * @return Visconte.Onto.OWLContainer - filled with OWLClass
392
 
 */
393
 
    public Visconte.Onto.OWLContainer get_equivalent_classes() 
394
 
    {        
395
 
       return ontology->get_Items(equivalent_Class);
396
 
    } 
397
 
 
398
 
 
399
 
/**
400
 
 * <p>Resets all restrictions of equivalent and different classes.</p>
401
 
 * 
402
 
 * 
403
 
 * @return 
404
 
 */
405
 
    public void unset_restrictions() 
406
 
    {     
407
 
 
408
 
            foreach(equivalent_Class, string id)
409
 
                    unset_equivalent_class(id);
410
 
 
411
 
           
412
 
            foreach(different_From, string id)
413
 
                    unset_different_from_class(id);
414
 
    }
415
 
            
416
 
/**
417
 
 * <p>Unset a class from the equal state.</p>
418
 
 * TODO: Allow OWLClass object as param
419
 
 * @param string id of the class
420
 
 * @return int
421
 
 */
422
 
    public int unset_equivalent_class(string id) 
423
 
    {    
424
 
            
425
 
       if(has_equivalent_class(id))
426
 
       {
427
 
               //remove it here
428
 
               int pos = (search(equivalent_Class,id));
429
 
               equivalent_Class-=({equivalent_Class[pos]});
430
 
               ontology->update(this_object());
431
 
               //remove the equivalent_class on the other side of "equal sign"
432
 
               OWLClass mirror_class= ontology->get_Class(id);
433
 
               mirror_class->unset_equivalent_class(this_program::id);
434
 
               ontology->update(mirror_class);
435
 
               return 1; 
436
 
       }
437
 
       else
438
 
               return 0;
439
 
    } 
440
 
    
441
 
    
442
 
/**
443
 
 * <p>Set an Class equivalent</p>
444
 
 * TODO: Allow OWLClass object as param
445
 
 * @param string id of the class
446
 
 * @return int 0|1
447
 
 */
448
 
    public int set_equivalent_class(string id) 
449
 
    {    
450
 
            
451
 
            
452
 
       //if this item is not in the ontology        
453
 
       if(!ontology->item_exists(this_program::id))
454
 
               return 0;
455
 
       //iam always equal myself, no need to mention it
456
 
       if(id==this_program::id)
457
 
               return 0;
458
 
       if(has_different_from_class(id))
459
 
                 unset_different_from_class(id); 
460
 
 
461
 
       if(!has_equivalent_class(id))
462
 
       {
463
 
                if(ontology->item_exists(id))
464
 
                {
465
 
                              //add it here;
466
 
                              equivalent_Class+=({id});
467
 
                              ontology->update(this_object());
468
 
                              //add the equivalent_class on the other side of "equal sign"
469
 
                              OWLClass mirror_class= ontology->get_Class(id);
470
 
                              mirror_class->set_equivalent_class(this_program::id);
471
 
                              ontology->update(mirror_class);
472
 
                            
473
 
                }
474
 
                return 1;
475
 
       }
476
 
       return 0;
477
 
    } 
478
 
    
479
 
    
480
 
/**
481
 
 * <p>Test if this class is equivaletent to another</p>
482
 
 * Note: This is not test euality of two object, rather semantical euivalent
483
 
 * TODO: Allow OWLClass object as param
484
 
 * @param string id of the class
485
 
 * @return int 0|1
486
 
 */
487
 
    public int has_equivalent_class(string id) 
488
 
    {        
489
 
       if(search(equivalent_Class,id)>=0)
490
 
               return 1;
491
 
       else
492
 
               return 0;
493
 
    } 
494
 
 
495
 
    
496
 
    
497
 
/**
498
 
 * <p></p>
499
 
 * 
500
 
 * 
501
 
 * @return 
502
 
 */
503
 
    public int set_different_from_class(string id) 
504
 
    {    
505
 
            
506
 
        //if this item is not in the ontology       
507
 
       if(!ontology->item_exists(this_program::id)) 
508
 
               return 0;
509
 
       //cannot be different from myself
510
 
       if(id==this_program::id)
511
 
               return 0;
512
 
        if(has_equivalent_class(id))
513
 
                 unset_equivalent_class(id);        
514
 
       if(!has_different_from_class(id))
515
 
       {
516
 
               if(ontology->item_exists(id))
517
 
               {
518
 
                       //add it here
519
 
                       different_From+=({id});
520
 
                       ontology->update(this_object());
521
 
                       //add the different_from class on the other side of "unequal sign"
522
 
                       OWLClass mirror_class= ontology->get_Class(id);
523
 
                       mirror_class->set_different_from_class(this_program::id);
524
 
                       ontology->update(mirror_class);
525
 
                     
526
 
               }
527
 
 
528
 
               
529
 
       }
530
 
    } 
531
 
    
532
 
/**
533
 
 * <p>Unset a Class differentFrom</p>
534
 
 * TODO: Allow OWLClass object as param
535
 
 * @param string id of the class
536
 
 * @return int 0|1
537
 
 */
538
 
    public int unset_different_from_class(string id) 
539
 
    {    
540
 
            
541
 
       if(has_different_from_class(id))
542
 
       {
543
 
               //remove it here
544
 
               int pos = (search(different_From,id));
545
 
               different_From-=({ different_From[pos] });
546
 
               ontology->update(this_object());
547
 
               //remove the different_from class on the other side of "unequal sign"
548
 
               OWLClass mirror_class= ontology->get_Class(id);
549
 
               mirror_class->set_different_from_class(this_program::id);
550
 
               ontology->update(mirror_class);
551
 
               
552
 
               return 1;
553
 
       }
554
 
       else
555
 
               return 0;
556
 
    } 
557
 
    
558
 
/**
559
 
 * <p>Tests if a Class differentFrom</p>
560
 
 * TODO: Allow OWLClass object as param
561
 
 * @param string id of the class
562
 
 * @return int 0|1
563
 
 */
564
 
    public int has_different_from_class(string id) 
565
 
    {        
566
 
       if(search(different_From,id)>=0)
567
 
               return 1;
568
 
       else
569
 
               return 0;
570
 
    }       
571
 
       
572
 
/**
573
 
 * <p>Get all Classes which are differentFrom this class</p>
574
 
 * Note: This is semantical difference
575
 
 * @return Visconte.Onto.OWLContainer - filled with OWLClass objects
576
 
 */
577
 
    public Visconte.Onto.OWLContainer get_different_from_classes() 
578
 
    {        
579
 
       return ontology->get_Items(different_From);
580
 
    } 
581
 
  
582
 
 
583
 
 
584
 
  /**
585
 
 * <p>Test if this class has child resp subclasses</p>
586
 
 * 
587
 
 * 
588
 
 * @return int 0 or number of childs
589
 
 */
590
 
    public int has_childs() 
591
 
    {        
592
 
       return sizeof(childs);
593
 
    } 
594
 
    
595
 
/**
596
 
 * <p>Get all direct childs of this class</p>
597
 
 * 
598
 
 * 
599
 
 * @return Visconte.Onto.OWLContainer - filled with OWLClass
600
 
 */
601
 
    public Visconte.Onto.OWLContainer get_childs() 
602
 
    {        
603
 
       return ontology->get_Items(childs);
604
 
    } 
605
 
 
606
 
 
607
 
/**
608
 
 * <p>Get all childs of the underlying subtree</p>
609
 
 * 
610
 
 * 
611
 
 * @return Visconte.Onto.OWLContainer - filled with OWLClass
612
 
 */
613
 
    public Visconte.Onto.OWLContainer get_all_childs() 
614
 
    {      
615
 
            Visconte.Onto.OWLContainer child_container  = Visconte.Onto.OWLContainer();
616
 
            Visconte.Onto.OWLContainer tmp_container  = get_childs();
617
 
            while(tmp_container->has_items())
618
 
            {
619
 
                    OWLItem item = tmp_container->next();
620
 
                    child_container->add(item);
621
 
                    child_container->merge(item->get_all_childs());
622
 
            }
623
 
            return child_container;
624
 
    } 
625
 
    
626
 
/**
627
 
 * <p>Test if this it the root class</p>
628
 
 * The root class is #Thing
629
 
 * 
630
 
 * @return int 0|1
631
 
 */
632
 
    public int is_root() 
633
 
    {    
634
 
            if(id=="#Thing" || id=="Thing" || id=="owl:Thing")
635
 
                    return 1;
636
 
            else
637
 
                    return 0;
638
 
    }
639
 
 
640
 
    
641
 
/**
642
 
 * <p>Checkif this class is an descendant of the other class</p>
643
 
 * 
644
 
 * @param OWLClass|string the class or id  where this is descendant of 
645
 
 * @return 0|1
646
 
 */
647
 
    public int is_descendant_of(OWLClass|string owl_class) 
648
 
    {  
649
 
            OWLClass _class = ontology->get_Item(get_Id());
650
 
            OWLClass possible_ancestor;
651
 
            if(stringp(owl_class))
652
 
            {
653
 
                    possible_ancestor = ontology->get_Item(owl_class);
654
 
            }
655
 
            else
656
 
                    possible_ancestor = owl_class;
657
 
            
658
 
            if(possible_ancestor->is_root())
659
 
            {
660
 
                    return 1;
661
 
            }
662
 
            
663
 
            while(_class!=0)
664
 
            {
665
 
                    if(possible_ancestor->is_equal(_class) )
666
 
                    {
667
 
                            return 1;
668
 
                            break;
669
 
                            
670
 
                    }
671
 
                    if(_class->is_root())
672
 
                    {
673
 
                            return 0;
674
 
                            break;
675
 
                    }
676
 
                    
677
 
                    _class=_class->get_parent();
678
 
            }
679
 
            return 0;
680
 
    }
681
 
            
682
 
/**
683
 
 * <p>Checks if this class has a parent class</p>
684
 
 * Only false if this is the root class
685
 
 * 
686
 
 * @return 0|1
687
 
 */
688
 
    public int has_parent() 
689
 
    {        
690
 
            if(ontology->item_exists(parent_id) && !is_root())
691
 
            {
692
 
                    return 1;
693
 
            }
694
 
            else
695
 
                    return 0;
696
 
    }
697
 
    
698
 
/**
699
 
 * <p>Get the parent class of this class, if exists</p>
700
 
 * Note: This implemenation focus on a single inheritance
701
 
 * 
702
 
 * @return OWLClass - the parent class
703
 
 */
704
 
    public OWLClass get_parent() 
705
 
    {        
706
 
           if(has_parent())
707
 
                    return ontology->get_Class(parent_id);
708
 
           else
709
 
                    return 0;
710
 
           
711
 
    } 
712
 
 
713
 
/**
714
 
 * <p>Set a new parent class</p>
715
 
 * 
716
 
 * 
717
 
 * @param OWLClass - the new parent
718
 
 */
719
 
    public void set_parent(OWLClass parent) 
720
 
    {        
721
 
         if(parent->get_Id()==0)
722
 
                this_program::parent_id=Visconte.Onto.Ontology.THING;
723
 
         else
724
 
                this_program::parent_id=parent->get_Id();
725
 
    } 
726
 
    
727
 
/**
728
 
 * <p>Returns all individuals of this branch (up and down)</p>
729
 
 * This will retrieve all individuals which are in the branch of this class (from root to the leafes)
730
 
 * 
731
 
 * @return Visconte.Onto.OWLContainer - filled with OWLIndividual
732
 
 */
733
 
    public Visconte.Onto.OWLContainer get_all_individuals() 
734
 
    {
735
 
            Visconte.Onto.OWLContainer ind = get_individuals_up_to_root();
736
 
            ind->merge(get_individuals_down_to_leaf());
737
 
            return ind;
738
 
    }
739
 
    
740
 
/**
741
 
 * <p>Get individuals of this class and the parent classes</p>
742
 
 * 
743
 
 * 
744
 
 * @return Visconte.Onto.OWLContainer - filled with OWLIndividual 
745
 
 */
746
 
    public Visconte.Onto.OWLContainer get_individuals_up_to_root() 
747
 
    {  
748
 
           Visconte.Onto.OWLContainer ind = get_individuals() ;
749
 
           if(has_parent())
750
 
           {
751
 
                 OWLClass parent  = get_parent();
752
 
                 
753
 
                 ind->merge(parent->get_individuals_up_to_root());
754
 
                   
755
 
           }
756
 
          return ind;
757
 
    } 
758
 
    
759
 
    
760
 
    
761
 
    
762
 
/**
763
 
 * <p>Get individuals of this class and all subclasses</p>
764
 
 * 
765
 
 * 
766
 
 * @return Visconte.Onto.OWLContainer - filled with OWLIndividual 
767
 
 */
768
 
    public Visconte.Onto.OWLContainer get_individuals_down_to_leaf() 
769
 
    {  
770
 
           Visconte.Onto.OWLContainer ind = get_individuals() ;
771
 
           if(has_childs())
772
 
           {
773
 
                 Visconte.Onto.OWLContainer  child_container = get_childs();
774
 
                   while(child_container->has_items())
775
 
                   {
776
 
                           ind->merge(child_container->next()->get_individuals_down_to_leaf());
777
 
                   }  
778
 
           }
779
 
          return ind;
780
 
    } 
781
 
    
782
 
    
783
 
/**
784
 
 * <p>Get individuals of this class only</p>
785
 
 * 
786
 
 * 
787
 
 * @return Visconte.Onto.OWLContainer - filled with OWLIndividual 
788
 
 */
789
 
    public Visconte.Onto.OWLContainer get_individuals() 
790
 
    {       
791
 
       return ontology->get_Items(individuals);
792
 
    } 
793
 
 
794
 
 
795
 
/**
796
 
 * <p>Get the number of individuals where this class is the template</p>
797
 
 * This will return only the number of individuals of this class, not the inherited ones
798
 
 * 
799
 
 * @return int - count
800
 
 */
801
 
    public int get_number_of_indivduals() 
802
 
    {        
803
 
            return sizeof(individuals);
804
 
        
805
 
    } 
806
 
 
807
 
/**
808
 
 * <p>Get the weight of  this class in relation to its depth in the tree level<p>
809
 
 * The weight is the addition of all individuals of the subclasses and the number of individuals of this class
810
 
 * 
811
 
 * @param int add - add this amount to the weight of all classes in the branch
812
 
 *                  (usefull within visconte browser for treemap appearance)
813
 
 * @return int count 
814
 
 */
815
 
    public int get_weight(int add) 
816
 
    {        
817
 
           
818
 
           int weight = get_number_of_indivduals();
819
 
          
820
 
           if(has_childs())
821
 
           {
822
 
                   Visconte.Onto.OWLContainer  child_container = get_childs();
823
 
                   while(child_container->has_items())
824
 
                   {
825
 
                           weight+=child_container->next()->get_weight(add);
826
 
                   }
827
 
                    return weight;
828
 
           }
829
 
           else
830
 
                  return weight+add;
831
 
        
832
 
    }     
833
 
 
834
 
   
835
 
} //}}}
836
 
 
837
 
/**   
838
 
*       I N D I V I D U A L S
839
 
840
 
* <p>class OWLIndividual - Represents an Instance of a class</p>
841
 
* see Comment Header in OWLItem for more details!
842
 
*/
843
 
class OWLIndividual
844
 
{
845
 
inherit OWLItem;
846
 
 
847
 
 
848
 
 
849
 
/**
850
 
 * <p>Represents the type of the item, which is INDIVIDUAL here</p>
851
 
 */
852
 
    public constant ITEMTYPE = INDIVIDUAL;
853
 
 
854
 
/**
855
 
 * <p>Represents the id of the model class </p>
856
 
 */
857
 
    private string class_id;
858
 
    
859
 
/**
860
 
 * <p>Array with all valid properties of this individual</p>
861
 
 */
862
 
    private Visconte.Onto.OWLContainer properties;
863
 
    
864
 
    
865
 
/**
866
 
 * <p>Array with all associations of this individual</p>
867
 
 */
868
 
    private array association_ids =({});
869
 
 
870
 
/**
871
 
 * <p>Array with all valid properties of this individual</p>
872
 
 */
873
 
    private array(array(mixed)) property_map =({});
874
 
 
875
 
 
876
 
/**
877
 
 * <p>Constructor: creates an OWLIndividual. If you want to create an item which isnt in the ontology, 
878
 
 * use the OWLItemFactory to construct the Individual</p>
879
 
 * 
880
 
 * @param ontology The associated Ontology
881
 
 * @param id - the id of the individual
882
 
 * @param class_id -the id of the model class
883
 
 * @param label - mapping with lang:label items
884
 
 * @param properties - the properties which are allowed for this individual (get from model class and its parents)
885
 
 * @param property_values - the Visconte.MVList with the id to value(s) statements
886
 
 *
887
 
 * 
888
 
 */
889
 
    public void create( Visconte.Onto.Ontology ontology, string id, string class_id, mapping label, Visconte.Onto.OWLContainer properties, Visconte.MVList property_values) 
890
 
    {        
891
 
                this_program::ontology=ontology;
892
 
                this_program::id=id;
893
 
                this_program::class_id=class_id;
894
 
                if(label)
895
 
                        this_program::label=label;
896
 
                this_program::properties = properties;
897
 
                //set the property values to the matching property
898
 
                if(property_values)
899
 
                set_Properties(property_values);
900
 
                
901
 
    } 
902
 
    
903
 
 
904
 
/**
905
 
 * <p>Checks if this individual is a document term</p>
906
 
 * 
907
 
 * 
908
 
 * @return nothing
909
 
 */
910
 
    public int is_document_term() 
911
 
    { 
912
 
            return this_object()->get_model_class()->is_document_term();
913
 
    }
914
 
    
915
 
 /**
916
 
 * <p>Return the obejctid and the mimetype of a document individual</p>
917
 
 * 
918
 
 * 
919
 
 * @return nothing
920
 
 */
921
 
    public mapping get_steam_properties() 
922
 
    { 
923
 
            if(is_document_term())
924
 
                    return ontology->get_steam_properties(this_object());
925
 
            else
926
 
                    return ([ "objectid" : "-1", "mimetype" : "-1" ]);
927
 
    }
928
 
    
929
 
       
930
 
/**
931
 
 * <p>Method to set an Visconte.MVList with index:property value pairs to this individual
932
 
 * It will call the set_Property method to validate the items</p>
933
 
 * 
934
 
 * 
935
 
 * @return nothing
936
 
 */
937
 
    public void set_Properties(Visconte.MVList property_values) 
938
 
    {     
939
 
          
940
 
            array indexes = property_values->get_indexes();
941
 
            //reset current properties
942
 
           
943
 
            foreach(indexes,string index)
944
 
            {
945
 
                    foreach(property_values->get(index), string value)
946
 
                    set_Property(index,value);
947
 
            }
948
 
    }
949
 
/**
950
 
 * <p>Returns the model class, from which this individual is derived</p>
951
 
 * 
952
 
 * 
953
 
 * @return the model class as OWLClass
954
 
 */
955
 
    public OWLClass reset_properties() {
956
 
            association_ids =({});
957
 
            property_map =({});
958
 
    }
959
 
     
960
 
/**
961
 
 * <p>Returns the model class, from which this individual is derived</p>
962
 
 * 
963
 
 * 
964
 
 * @return the model class as OWLClass
965
 
 */
966
 
    public OWLClass get_model_class() {        
967
 
            
968
 
            return ontology->get_Item(class_id);
969
 
    } 
970
 
    
971
 
/**
972
 
 * <p>This sets a new model class for this individual</p>
973
 
 * 
974
 
 * 
975
 
 * @param class the new model class
976
 
 */
977
 
    public void set_model_class(OWLClass owl_class) {        
978
 
        
979
 
            this_program::class_id=owl_class->get_Id();
980
 
    } 
981
 
    
982
 
/**
983
 
 * <p>This method returns checks for the existence
984
 
 * resp. if this property is set.</p>
985
 
 * 
986
 
 * 
987
 
 * @return the multi value property list 
988
 
 */
989
 
    public int has_property(OWLProperty|string property) 
990
 
    {        
991
 
        string property_search_id;
992
 
        if(objectp(property))
993
 
                property_search_id=property->get_Id();
994
 
        else
995
 
                property_search_id=property;
996
 
        
997
 
        foreach(property_map,array prop_value)
998
 
        {
999
 
                if(prop_value[0]->get_Id()==property_search_id)
1000
 
                        break;
1001
 
                        return 1;
1002
 
        }
1003
 
        
1004
 
        return 0;
1005
 
    }
1006
 
    
1007
 
 
1008
 
    
1009
 
    
1010
 
/**
1011
 
 * <p>This method returns the value(s) of a property</p>
1012
 
 * 
1013
 
 * 
1014
 
 * @return array with property definition
1015
 
 
1016
 
    public array get_property(OWLProperty|string property) 
1017
 
    {        
1018
 
        string property_id;
1019
 
        if(objectp(property))
1020
 
                property_id=property->get_Id();
1021
 
        else
1022
 
                property_id=property;
1023
 
        
1024
 
        foreach(property_map,array prop_value)
1025
 
        {
1026
 
                if(prop_value[0]->get_ID()==property_search_id)
1027
 
                        break;
1028
 
                        return 1;
1029
 
        }
1030
 
        
1031
 
        return 0;
1032
 
    }
1033
 
     */
1034
 
/**
1035
 
 * <p>This method returns the Visconte.MVList of properties.</p>
1036
 
 * 
1037
 
 * 
1038
 
 * @return the multi value property list 
1039
 
 */
1040
 
    public Visconte.MVList get_property_list() 
1041
 
    {       
1042
 
        Visconte.MVList property_mv_list = Visconte.MVList();
1043
 
        foreach(property_map,array prop_value)
1044
 
        {
1045
 
                if(prop_value[0]->ITEMTYPE==Visconte.Onto.Item.OWLItem.OBJECT_PROPERTY)
1046
 
                        property_mv_list->add(prop_value[0]->get_Id(),prop_value[1]->get_Id());
1047
 
                else
1048
 
                        property_mv_list->add(prop_value[0]->get_Id(),prop_value[1]);
1049
 
        }
1050
 
        return property_mv_list;
1051
 
    } 
1052
 
 
1053
 
/**
1054
 
* <p>Get OWLContainer with all associated individuals
1055
 
 * 
1056
 
 * 
1057
 
 * @return Visconte.Onto.OWLContainer - filled with OWLIndividuals
1058
 
 */
1059
 
    public Visconte.Onto.OWLContainer get_associations() 
1060
 
    {        
1061
 
        return ontology->get_Items(association_ids);
1062
 
    }
1063
 
 
1064
 
/**
1065
 
* <p>Test if this Individual is associated with the given one
1066
 
 * 
1067
 
 * 
1068
 
 * @return int 0|1
1069
 
 */
1070
 
    public int is_associated_with(OWLIndividual|string individual) 
1071
 
    {        
1072
 
            string ind_id;
1073
 
            if(objectp(individual))
1074
 
                ind_id=individual->get_Id();
1075
 
            else
1076
 
                ind_id=individual;
1077
 
            
1078
 
            if(has_value(association_ids,ind_id))
1079
 
                    return 1;
1080
 
            else
1081
 
                    return 0;
1082
 
    }
1083
 
    
1084
 
/**
1085
 
* <p>Remove all associations with the given individual
1086
 
 * 
1087
 
 * 
1088
 
 * @return int 0|1 success 
1089
 
 */
1090
 
    public int remove_associations_with(OWLIndividual|string individual) 
1091
 
    {
1092
 
            string ind_id;
1093
 
           
1094
 
            if(objectp(individual))
1095
 
                ind_id=individual->get_Id();
1096
 
            else
1097
 
                ind_id=individual;
1098
 
            if(is_associated_with(ind_id))
1099
 
            {  
1100
 
                   foreach(property_map,array property_set)
1101
 
                   {
1102
 
                           if(property_set[0]->ITEMTYPE==OBJECT_PROPERTY && property_set[1]==ind_id)
1103
 
                                remove_Property(property_set[0]);
1104
 
                   }
1105
 
                   
1106
 
                   return 1;
1107
 
            }
1108
 
            else
1109
 
                   return 0;
1110
 
    }
1111
 
 
1112
 
    /**
1113
 
* <p>Remove all associations with the given individual
1114
 
 * 
1115
 
 * 
1116
 
 * @return int 0|1 success 
1117
 
 */
1118
 
    public int replace_individual(OWLIndividual|string individual, OWLIndividual new_id) 
1119
 
    {
1120
 
            string ind_id;
1121
 
            array(array(mixed)) tmp_map =({});
1122
 
            if(objectp(individual))
1123
 
                ind_id=individual->get_Id();
1124
 
            else
1125
 
                ind_id=individual;
1126
 
            if(is_associated_with(ind_id))
1127
 
            {  
1128
 
                   foreach(property_map,array property_set)
1129
 
                   {
1130
 
                           if(property_set[0]->ITEMTYPE==OBJECT_PROPERTY && property_set[1]==ind_id)
1131
 
                                property_set[1]=new_id->get_Id();
1132
 
                           tmp_map+=({property_set});
1133
 
                          
1134
 
                   }
1135
 
                   this_program::property_map = tmp_map;
1136
 
                   return 1;
1137
 
            }
1138
 
            else
1139
 
                   return 0;
1140
 
    }
1141
 
        
1142
 
/**
1143
 
 * <p>This method returns an array with the ordering ({ ({ OWLProperty, (string) value})[0..*] })
1144
 
 *    used for the xml constuction
1145
 
 * 
1146
 
 * 
1147
 
 * @return the property map as array
1148
 
 */
1149
 
    public array get_property_map() 
1150
 
    {        
1151
 
        return property_map;
1152
 
    }
1153
 
    
1154
 
 
1155
 
 
1156
 
/**
1157
 
 * <p>This method sets a property to the individual
1158
 
 * <li>First its checks if the propagated id is a valid property for this 
1159
 
 * individual (by checking for equality of the property domain and the model class of this individual
1160
 
 * </li>
1161
 
 * <li>Then it test if the value is an ObjectProperty and if the given value is an existing instance
1162
 
 * in the ontology. If so, it will be added to the property list and to the property map. The tests for
1163
 
 * a datatype are similar, except the test for a valid value</p>
1164
 
 * 
1165
 
 * 
1166
 
 * @param id - the id of the property 
1167
 
 * @param value - either the id of connected individual or a xsd: datatype (depends on property type) 
1168
 
 
1169
 
 */
1170
 
    public void set_Property(string id, string value) 
1171
 
    {     
1172
 
            OWLItem property;
1173
 
            property = this_program::properties->find_by_id(id);
1174
 
             
1175
 
            //1st test for the existence in the valid properties
1176
 
            if(property)
1177
 
            {
1178
 
                    //if its an ObjectProperty, test for a valid individual
1179
 
                    //and if the model class of the individual is the same
1180
 
                    // as the range type of the Property
1181
 
                    if(property->ITEMTYPE==OBJECT_PROPERTY)
1182
 
                    {
1183
 
                         if(ontology->item_exists(value))
1184
 
                         {      
1185
 
                                
1186
 
                                 //get the model class of this individual
1187
 
                                 //get_items_by_subject avoids a ping-pong effect on individuals refering each other  
1188
 
                                  OWLClass model_class = ontology->get_items_by_subject(value,2,CLASS)->next();
1189
 
                                
1190
 
                                 //test for equality of the values modelclass (and its parents) and Property range class
1191
 
                                 // and dont associate with itself
1192
 
                                 if(model_class->is_descendant_of(property->get_range()) && get_Id()!=value)
1193
 
                                 {
1194
 
                                         
1195
 
                                         // add the value to OWLProperty object
1196
 
                                         property_map+=({ ({ property, value}) }); 
1197
 
                                         // add the id to the association_id array
1198
 
                                         association_ids+=({value});
1199
 
                                 }
1200
 
                         }
1201
 
                    }
1202
 
                    //if its a datatype property, proceed here
1203
 
                    else
1204
 
                    {
1205
 
                            //see above...
1206
 
                            property_map+=({ ({ property, value}) }); 
1207
 
                    }
1208
 
            }               
1209
 
               
1210
 
               
1211
 
    } 
1212
 
 
1213
 
/**
1214
 
 * <p>Removes an property from the indiviudal,
1215
 
 * NOTE: it removes all property values which are "derived" from this property
1216
 
 * If a single index:value pair should be removed, use method: remove_index_value_pair()</p>
1217
 
 * 
1218
 
 * @param OWLProperty - the property to remove
1219
 
 * @return int 0|1 
1220
 
 */
1221
 
    public int remove_Property(OWLProperty property) 
1222
 
    {        
1223
 
        foreach(property_map,array prop_value)
1224
 
        {
1225
 
                if(prop_value[0]->get_Id()==property->get_Id())
1226
 
                        property_map-=({prop_value});
1227
 
        }
1228
 
        return 1;
1229
 
    } 
1230
 
 
1231
 
/**
1232
 
 * <p>Removes an property from the indiviudal,
1233
 
 * NOTE: it removes all property values which are "derived" from this property
1234
 
 * If a single index:value pair should be removed, use method: remove_index_value_pair()</p>
1235
 
 * 
1236
 
 * @param OWLProperty - the property to remove
1237
 
 * @return int 0|1 
1238
 
 */
1239
 
    public int replace_Property(OWLProperty old_property, OWLProperty new_property) {        
1240
 
        
1241
 
        foreach(property_map,array prop_value)
1242
 
        {
1243
 
                if(prop_value[0]->get_Id()==new_property->get_Id())
1244
 
                        property_map-=({prop_value});
1245
 
                        prop_value[0]=new_property;
1246
 
                        property_map+=({prop_value});
1247
 
        }
1248
 
        return 1;
1249
 
    }     
1250
 
/**
1251
 
 * <p>This method removes a single index value pair from this individual</p>
1252
 
 * 
1253
 
 * 
1254
 
 * @param property 
1255
 
 */   
1256
 
    // public int remove_index_value_pair(string id, string value ) {        
1257
 
        
1258
 
        // foreach(property_map,array prop_value)
1259
 
        // {
1260
 
        //      if(property_set[0]->ITEMTYPE==OBJECT_PROPERTY)
1261
 
        //      if(prop_value[0]->get_Id()==new_property->get_Id() && property_set[1]==ind_id)
1262
 
        //              property_map-=({prop_value});
1263
 
        //              prop_value[0]=new_property;
1264
 
        //              property_map+=({prop_value});
1265
 
        // }
1266
 
    // }
1267
 
    
1268
 
    
1269
 
    
1270
 
/**
1271
 
 * <p>This method returns checks for the existence
1272
 
 * resp. if this property is set.</p>
1273
 
 * 
1274
 
 * 
1275
 
 * @return the multi value property list 
1276
 
 */
1277
 
    // public int has_index_value_pair(OWLProperty|string property, string value) 
1278
 
    // {        
1279
 
    //     string property_id;
1280
 
        // if(objectp(property))
1281
 
        //      property_id=property->get_Id();
1282
 
        // else
1283
 
        //      property_id=property;
1284
 
        // write("has_index_value_pair: ix:"+property_id+", val"+value+"\n");
1285
 
        //test what type  of property we are testing for
1286
 
        // OWLProperty index_property = this_program::properties->find_by_id(property_id);
1287
 
        //if object property modify the id
1288
 
        // if(index_property->ITEMTYPE==OBJECT_PROPERTY)
1289
 
                        //value = Visconte.Tools()->flat_ID(value);
1290
 
        
1291
 
        // return property_mv_list->has_index_value(property_id, value);
1292
 
    // }    
1293
 
 
1294
 
} //end class OWLIndividual
1295
 
 
1296
 
/**
1297
 
 * <p>class OWLProperty - This class defines common methods for Object and Datatype Property</p>
1298
 
 * see Comment Header in OWLItem for more details!
1299
 
 *
1300
 
 *
1301
 
 *
1302
 
 *
1303
 
 * 
1304
 
 */
1305
 
class OWLProperty
1306
 
//{{{ 
1307
 
{
1308
 
inherit OWLItem;
1309
 
 
1310
 
 
1311
 
 
1312
 
/**
1313
 
 * <p>The bitset used for constraints like semtric propertie and so on</p>
1314
 
 */
1315
 
    protected int bitset = 0b00000;
1316
 
 
1317
 
/**
1318
 
 * <p>The domain of the property, which is in all cases a class</p>
1319
 
 */
1320
 
    static  OWLClass domain;
1321
 
 
1322
 
 
1323
 
 /**
1324
 
 * <p>Checks if this property is transitive.</p>
1325
 
 * 
1326
 
 * 
1327
 
 * @return int 0|1 
1328
 
 */
1329
 
    public int is_transitive() 
1330
 
    {        
1331
 
        if (bitset&0b00001)
1332
 
                return 1;
1333
 
        else
1334
 
                return 0;
1335
 
    } 
1336
 
 
1337
 
/**
1338
 
 * <p>Checks if this property is functional.</p>
1339
 
 * 
1340
 
 * 
1341
 
 * @return int 0|1  
1342
 
 */
1343
 
    public int is_functional() {        
1344
 
        if (bitset&0b00010)
1345
 
                return 1;
1346
 
        else
1347
 
                return 0;
1348
 
    } 
1349
 
 
1350
 
/**
1351
 
 * <p>Checks if this property is symetric..</p>
1352
 
 * 
1353
 
 * 
1354
 
 * @return int 0|1 
1355
 
 */
1356
 
    public int is_symetric() 
1357
 
    {        
1358
 
        if (bitset&0b00100)
1359
 
                return 1;
1360
 
        else
1361
 
                return 0;
1362
 
    } 
1363
 
 
1364
 
/**
1365
 
 * <p>Checks if this property is inverse of.</p>
1366
 
 * 
1367
 
 * 
1368
 
 * @return int 0|1 
1369
 
 */
1370
 
    public int is_inverse_of() 
1371
 
    {        
1372
 
        if (bitset&0b01000)
1373
 
                return 1;
1374
 
        else
1375
 
                return 0;
1376
 
    } 
1377
 
 
1378
 
/**
1379
 
 * <p>Checks if this property is inverse functional.</p>
1380
 
 * 
1381
 
 * 
1382
 
 * @return int 0|1 
1383
 
 */
1384
 
    public int is_inverse_functional() 
1385
 
    {        
1386
 
        if (bitset&0b10000)
1387
 
                return 1;
1388
 
        else
1389
 
                return 0;
1390
 
    } 
1391
 
 
1392
 
/**
1393
 
 * <p>Set the constraing bitset</p>
1394
 
 * 0b00000 - default
1395
 
 * 0b00001 - transitive
1396
 
 * 0b00010 - functional
1397
 
 * 0b00100 - symetric
1398
 
 * 0b10000 - inverse functional
1399
 
 *
1400
 
 * Note: up to now this is not function in the ontology script
1401
 
 * @param bitset 
1402
 
 */
1403
 
    public void set_restriction_bitset(int bitset) 
1404
 
    {        
1405
 
            this_program::bitset=bitset;
1406
 
    } 
1407
 
 
1408
 
 
1409
 
/**
1410
 
 * <p>Set the restriction by a string:int mapping</p>
1411
 
 * valid indexes and values
1412
 
 * are (transitive,functional,symetric,inverse,inverse_functional : 0|1)
1413
 
 * 
1414
 
 * @param mapping(string:int) - the restrictions
1415
 
 */
1416
 
    public void set_restriction(mapping restriction) 
1417
 
    {        
1418
 
            int set=0b00000;
1419
 
            if(restriction["transitive"]==1)
1420
 
                    set|=0b00001;
1421
 
            if(restriction["functional"]==1)
1422
 
                    set|=0b00010;
1423
 
            if(restriction["symetric"]==1)
1424
 
                    set|=0b00100;
1425
 
            if(restriction["inverse"]==1)
1426
 
                    set|=0b01000;
1427
 
            if(restriction["inverse_functional"]==1)
1428
 
                    set|=0b10000;
1429
 
            
1430
 
            this_program::bitset=set;
1431
 
            
1432
 
            
1433
 
    } 
1434
 
/**
1435
 
 * <p>Returns the domain of this property</p>
1436
 
 * 
1437
 
 * 
1438
 
 * @return OWLClass - the domain class
1439
 
 */
1440
 
    public OWLClass get_domain() {        
1441
 
       return domain;
1442
 
    } 
1443
 
    
1444
 
    
1445
 
/**
1446
 
 * <p>Set a new domain to this property</p>
1447
 
 * 
1448
 
 * @param OWLClass - the new domain class
1449
 
 * @return 
1450
 
 */
1451
 
    public OWLClass set_domain(OWLClass domain) {        
1452
 
       this_program::domain = domain;
1453
 
    } 
1454
 
 
1455
 
 
1456
 
    
1457
 
/**
1458
 
 * <p>Returns all individuals with this property (individuals of the domain)</p>
1459
 
 * This will do the same like the method get_individuals_down_to_leaf() in OWLClass
1460
 
 * 
1461
 
 * @return 
1462
 
 */
1463
 
    public Visconte.Onto.OWLContainer get_individuals() 
1464
 
    {        
1465
 
        return domain->get_individuals_down_to_leaf();
1466
 
    } 
1467
 
 
1468
 
 
1469
 
 
1470
 
} //}}}
1471
 
 
1472
 
 
1473
 
 
1474
 
 
1475
 
/**
1476
 
 * <p>class OWLObjectProperty - Represents an OWL ObjectProperty, which is also named an association in this library</p>
1477
 
 * see Comment Header in OWLItem for more details!
1478
 
 */
1479
 
class OWLObjectProperty
1480
 
//{{{ 
1481
 
{
1482
 
inherit OWLProperty;
1483
 
 
1484
 
/**
1485
 
 * <p>Represents the type of the item, which is CLASS here</p>
1486
 
 */
1487
 
    public constant ITEMTYPE = OBJECT_PROPERTY;
1488
 
 
1489
 
    
1490
 
/**
1491
 
 * <p>The Range class of this object</p>
1492
 
 */
1493
 
    private  OWLClass range;
1494
 
    
1495
 
    
1496
 
    
1497
 
/**
1498
 
 * <p>Construct an ObjectProperty</p>
1499
 
 * @param ontology - the ontology object to operate on
1500
 
 * @param id - the id of this Object Property
1501
 
 * @param restrictions - a mapping with the restrictions (see set_restriction() in OWLProperty)
1502
 
 * @param mapping label - the label or name of this property
1503
 
 * @param OWLClass domain - the domain of this property
1504
 
 * @param OWLClass range - the range of this property
1505
 
 * @return 
1506
 
 */
1507
 
 
1508
 
   public void create(Visconte.Onto.Ontology ontology, string id,  mapping restriction, mapping label, OWLClass domain, OWLClass range)
1509
 
   {
1510
 
           this_program::ontology=ontology;
1511
 
           this_program::id=id;
1512
 
           this_program::label=label;
1513
 
           set_restriction(restriction);
1514
 
           this_program::domain=domain;
1515
 
           this_program::range=range;
1516
 
           
1517
 
               
1518
 
   }
1519
 
   
1520
 
/**
1521
 
 * <p>Get the range Class of this property</p>
1522
 
 * 
1523
 
 * @return OWLClass - the range class
1524
 
 */
1525
 
    public OWLClass get_range() {        
1526
 
        return range;
1527
 
    } 
1528
 
    
1529
 
/**
1530
 
 * <p>Set a new Range class</p>
1531
 
 * 
1532
 
 * @param OWLClass - the new range
1533
 
 */
1534
 
    public int set_range(OWLItem range) {        
1535
 
        this_program::range=range;
1536
 
    }
1537
 
 
1538
 
 
1539
 
} //}}}
1540
 
 
1541
 
 
1542
 
 
1543
 
/**
1544
 
 * <p>class OWLDataytypeProperty -Represents an OWL Datatype</p>
1545
 
 * see Comment Header in OWLItem for more details!
1546
 
 */
1547
 
class OWLDatatypeProperty
1548
 
//{{{ 
1549
 
{
1550
 
inherit OWLProperty;
1551
 
 
1552
 
 
1553
 
 
1554
 
 
1555
 
/**
1556
 
 * <p>Represents the type of the item, which is CLASS here</p>
1557
 
 */
1558
 
    public constant ITEMTYPE = DATATYPE_PROPERTY;
1559
 
 
1560
 
/**
1561
 
 * <p>The range as string rpresentaion which is an xsd element (e.g string, anyURI etc.)</p>
1562
 
 */
1563
 
    private  string range;
1564
 
 
1565
 
/**
1566
 
 * <p>If no dataytype is specified use (xsd:)string</p>
1567
 
 */
1568
 
    private  string default_dataype="string";
1569
 
    
1570
 
/**
1571
 
 * <p>List of valid datatypes</p>
1572
 
 */
1573
 
    private array datatypes = ({"string",
1574
 
                                "normalizedString",
1575
 
                                "boolean",
1576
 
                                "decimal",
1577
 
                                "float",
1578
 
                                "double",
1579
 
                                "integer",
1580
 
                                "nonNegativeInteger",
1581
 
                                "positiveInteger",
1582
 
                                "nonPositiveInteger",
1583
 
                                "negativeInteger",
1584
 
                                "long",
1585
 
                                "int",
1586
 
                                "short",
1587
 
                                "byte",
1588
 
                                "unsignedLong",
1589
 
                                "unsignedInt",
1590
 
                                "unsignedShort",
1591
 
                                "unsignedByte",
1592
 
                                "hexBinary",
1593
 
                                "base64Binary",
1594
 
                                "dateTime",
1595
 
                                "time",
1596
 
                                "date",
1597
 
                                "gYearMonth",
1598
 
                                "gYear",
1599
 
                                "gMonthDay",
1600
 
                                "gDay",
1601
 
                                "gMonth",
1602
 
                                "anyURI",
1603
 
                                "token",
1604
 
                                "language",
1605
 
                                "NMTOKEN",
1606
 
                                "Name",
1607
 
                                "steamDoc",
1608
 
                                "steamUser",
1609
 
                                "steamGroup",
1610
 
                                "steamContainer",
1611
 
                              });
1612
 
    
1613
 
 
1614
 
/**
1615
 
 * <p>Construct a Datatype Property</p>
1616
 
 * @param ontology - the ontology object to operate on
1617
 
 * @param id - the id of this Datatype Property
1618
 
 * @param restrictions - a mapping with the restrictions (see set_restriction() in OWLProperty)
1619
 
 * @param mapping label - the label or name of this property
1620
 
 * @param OWLClass domain - the domain of this property
1621
 
 * @param string range - the range of this property (xsd element, with or without trailing xsd:)
1622
 
 * @return 
1623
 
 */
1624
 
 
1625
 
   public void create(Visconte.Onto.Ontology ontology, string id,  mapping restriction, mapping label, OWLClass domain, string range)
1626
 
   {
1627
 
           this_program::ontology=ontology;
1628
 
           this_program::id=id;
1629
 
           this_program::label=label;
1630
 
           set_restriction(restriction);
1631
 
           validate_datatype(range);
1632
 
           this_program::domain=domain;
1633
 
           
1634
 
               
1635
 
   }
1636
 
 
1637
 
/**
1638
 
 * <p>Returns the range </p>
1639
 
 * 
1640
 
 * @return string range 
1641
 
 */
1642
 
    public string get_range() {        
1643
 
        return range;
1644
 
    } 
1645
 
/**
1646
 
 * <p>Set a new range</p>
1647
 
 * 
1648
 
 * @param string range - xsd element, with or without trailing xsd:
1649
 
 */
1650
 
    public int set_range(string range) {        
1651
 
        validate_datatype(range);
1652
 
    } 
1653
 
    
1654
 
    
1655
 
    
1656
 
/**
1657
 
 * <p>Validates it the range is valid</p>
1658
 
 * If its not valid set to default_dataype 
1659
 
 * 
1660
 
 */
1661
 
   private void validate_datatype(string datatype)
1662
 
   {
1663
 
           //if the type has dataype xsd namepace set to string
1664
 
           if(!has_prefix(datatype,"xsd:"))
1665
 
                   this_program::range =  default_dataype;
1666
 
           else
1667
 
           {
1668
 
                   //try to find the datatype, else set to string
1669
 
                  int type = search(datatypes,datatype[4..]);
1670
 
                  if(type>=0)
1671
 
                          this_program::range=datatypes[type];
1672
 
                  else
1673
 
                          this_program::range=default_dataype;
1674
 
           }
1675
 
   }
1676
 
 
1677
 
} //}}}
1678