-
Notifications
You must be signed in to change notification settings - Fork 87
/
OntologyProperty.cs
833 lines (759 loc) · 30.1 KB
/
OntologyProperty.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
/*
// <copyright>
// dotNetRDF is free and open source software licensed under the MIT License
// -------------------------------------------------------------------------
//
// Copyright (c) 2009-2021 dotNetRDF Project (http://dotnetrdf.org/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
*/
using System;
using System.Collections.Generic;
using System.Linq;
namespace VDS.RDF.Ontology
{
/// <summary>
/// Class for representing a property in an Ontology.
/// </summary>
/// <remarks>
/// <para>
/// See <a href="http://www.dotnetrdf.org/content.asp?pageID=Ontology%20API">Using the Ontology API</a> for some informal documentation on the use of the Ontology namespace.
/// </para>
/// </remarks>
public class OntologyProperty
: OntologyResource
{
private const String PropertyDerivedProperty = "derivedProperty";
private const String PropertyDirectSubProperty = "directSubProperty";
private const String PropertyDirectSuperProperty = "directSuperProperty";
/// <summary>
/// Creates a new Ontology Property for the given resource in the given Graph.
/// </summary>
/// <param name="resource">Resource.</param>
/// <param name="graph">Graph.</param>
public OntologyProperty(INode resource, IGraph graph)
: base(resource, graph)
{
// Q: Assert that this resource is a property?
// UriNode rdfType = graph.CreateUriNode(new Uri(OntologyHelper.PropertyType));
// graph.Assert(new Triple(resource, rdfType, graph.CreateUriNode(new Uri(OntologyHelper.RdfProperty))));
IntialiseProperty(OntologyHelper.PropertyDomain, false);
IntialiseProperty(OntologyHelper.PropertyRange, false);
IntialiseProperty(OntologyHelper.PropertyEquivalentProperty, false);
IntialiseProperty(OntologyHelper.PropertySubPropertyOf, false);
IntialiseProperty(OntologyHelper.PropertyInverseOf, false);
// Find derived properties
IUriNode subPropertyOf = _graph.CreateUriNode(UriFactory.Create(OntologyHelper.PropertySubPropertyOf));
_resourceProperties.Add(PropertyDerivedProperty, new HashSet<INode>());
_resourceProperties.Add(PropertyDirectSubProperty, new HashSet<INode>());
foreach (Triple t in _graph.GetTriplesWithPredicateObject(subPropertyOf, _resource))
{
_resourceProperties[PropertyDerivedProperty].Add(t.Subject);
_resourceProperties[PropertyDirectSubProperty].Add(t.Subject);
}
int c = 0;
do
{
c = _resourceProperties[PropertyDerivedProperty].Count;
foreach (INode n in _resourceProperties[PropertyDerivedProperty].ToList())
{
foreach (Triple t in _graph.GetTriplesWithPredicateObject(subPropertyOf, n))
{
_resourceProperties[PropertyDerivedProperty].Add(t.Subject);
}
}
} while (c < _resourceProperties[PropertyDerivedProperty].Count);
// Find additional super properties
_resourceProperties.Add(PropertyDirectSuperProperty, new HashSet<INode>());
if (_resourceProperties.ContainsKey(OntologyHelper.PropertySubPropertyOf))
{
foreach (var node in _resourceProperties[OntologyHelper.PropertySubPropertyOf])
{
_resourceProperties[PropertyDirectSuperProperty].Add(node);
}
do
{
c = _resourceProperties[OntologyHelper.PropertySubPropertyOf].Count;
foreach (INode n in _resourceProperties[OntologyHelper.PropertySubPropertyOf].ToList())
{
foreach (Triple t in _graph.GetTriplesWithSubjectPredicate(n, subPropertyOf))
{
_resourceProperties[OntologyHelper.PropertySubPropertyOf].Add(t.Object);
}
}
} while (c < _resourceProperties[OntologyHelper.PropertySubPropertyOf].Count);
}
// Find additional inverses
if (!_resourceProperties.ContainsKey(OntologyHelper.PropertyInverseOf))
_resourceProperties.Add(OntologyHelper.PropertyInverseOf, new HashSet<INode>());
foreach (Triple t in _graph.GetTriplesWithPredicateObject(
graph.CreateUriNode(UriFactory.Create(OntologyHelper.PropertyInverseOf)), _resource))
{
_resourceProperties[OntologyHelper.PropertyInverseOf].Add(t.Subject);
}
}
/// <summary>
/// Creates a new RDFS Ontology Property for the given resource in the given Graph.
/// </summary>
/// <param name="resource">Resource.</param>
/// <param name="graph">Graph.</param>
public OntologyProperty(Uri resource, IGraph graph)
: this(graph.CreateUriNode(resource), graph) { }
/// <summary>
/// Adds a new domain for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddDomain(INode resource)
{
return AddResourceProperty(OntologyHelper.PropertyDomain, resource.CopyNode(_graph), true);
}
/// <summary>
/// Adds a new domain for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddDomain(Uri resource)
{
return AddDomain(_graph.CreateUriNode(resource));
}
/// <summary>
/// Adds a new domain for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddDomain(OntologyResource resource)
{
return AddDomain(resource.Resource);
}
/// <summary>
/// Clears all domains for the property.
/// </summary>
/// <returns></returns>
public bool ClearDomains()
{
return ClearResourceProperty(OntologyHelper.PropertyDomain, true);
}
/// <summary>
/// Removes a domain for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveDomain(INode resource)
{
return RemoveResourceProperty(OntologyHelper.PropertyDomain, resource.CopyNode(_graph), true);
}
/// <summary>
/// Removes a domain for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveDomain(Uri resource)
{
return RemoveDomain(_graph.CreateUriNode(resource));
}
/// <summary>
/// Removes a domain for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveDomain(OntologyResource resource)
{
return RemoveDomain(resource.Resource);
}
/// <summary>
/// Adds a new range for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddRange(INode resource)
{
return AddResourceProperty(OntologyHelper.PropertyRange, resource.CopyNode(_graph), true);
}
/// <summary>
/// Adds a new range for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddRange(Uri resource)
{
return AddRange(_graph.CreateUriNode(resource));
}
/// <summary>
/// Adds a new range for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddRange(OntologyResource resource)
{
return AddRange(resource.Resource);
}
/// <summary>
/// Clears all ranges for the property.
/// </summary>
/// <returns></returns>
public bool ClearRanges()
{
return ClearResourceProperty(OntologyHelper.PropertyRange, true);
}
/// <summary>
/// Removes a range for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveRange(INode resource)
{
return RemoveResourceProperty(OntologyHelper.PropertyRange, resource, true);
}
/// <summary>
/// Removes a range for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveRange(Uri resource)
{
return RemoveRange(_graph.CreateUriNode(resource));
}
/// <summary>
/// Removes a range for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveRange(OntologyResource resource)
{
return RemoveRange(resource.Resource);
}
/// <summary>
/// Adds a new equivalent property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddEquivalentProperty(INode resource)
{
return AddResourceProperty(OntologyHelper.PropertyEquivalentProperty, resource.CopyNode(_graph), true);
}
/// <summary>
/// Adds a new equivalent property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddEquivalentProperty(Uri resource)
{
return AddEquivalentProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Adds a new equivalent property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddEquivalentProperty(OntologyResource resource)
{
return AddEquivalentProperty(resource.Resource);
}
/// <summary>
/// Adds a new equivalent property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also adds this property as an equivalent property of the given property.
/// </remarks>
public bool AddEquivalentProperty(OntologyProperty property)
{
bool a = AddEquivalentProperty(property.Resource);
bool b = property.AddEquivalentProperty(_resource);
return (a || b);
}
/// <summary>
/// Clears all equivalent properties for this property.
/// </summary>
/// <returns></returns>
public bool ClearEquivalentProperties()
{
INode equivProp = _graph.CreateUriNode(UriFactory.Create(OntologyHelper.PropertyEquivalentProperty));
_graph.Retract(_graph.GetTriplesWithSubjectPredicate(_resource, equivProp).ToList());
_graph.Retract(_graph.GetTriplesWithPredicateObject(equivProp, _resource).ToList());
return ClearResourceProperty(OntologyHelper.PropertyEquivalentProperty, true);
}
/// <summary>
/// Removes an equivalent property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveEquivalentProperty(INode resource)
{
return RemoveResourceProperty(OntologyHelper.PropertyEquivalentProperty, resource.CopyNode(_graph), true);
}
/// <summary>
/// Removes an equivalent property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveEquivalentProperty(Uri resource)
{
return RemoveEquivalentProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Removes an equivalent property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveEquivalentProperty(OntologyResource resource)
{
return RemoveEquivalentProperty(resource.Resource);
}
/// <summary>
/// Removes an equivalent property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also removes this property as an equivalent property of the given property.
/// </remarks>
public bool RemoveEquivalentProperty(OntologyProperty property)
{
bool a = RemoveEquivalentProperty(property.Resource);
bool b = property.RemoveEquivalentProperty(_resource);
return (a || b);
}
/// <summary>
/// Adds an inverse property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddInverseProperty(INode resource)
{
return AddResourceProperty(OntologyHelper.PropertyInverseOf, resource.CopyNode(_graph), true);
}
/// <summary>
/// Adds an inverse property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddInverseProperty(Uri resource)
{
return AddInverseProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Adds an inverse property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddInverseProperty(OntologyResource resource)
{
return AddInverseProperty(resource.Resource);
}
/// <summary>
/// Adds an inverse property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also adds this property as an inverse property of the given property.
/// </remarks>
public bool AddInverseProperty(OntologyProperty property)
{
bool a = AddInverseProperty(property.Resource);
bool b = property.AddInverseProperty(_resource);
return (a || b);
}
/// <summary>
/// Removes all inverse properties for this property.
/// </summary>
/// <returns></returns>
public bool ClearInverseProperties()
{
INode inverseOf = _graph.CreateUriNode(UriFactory.Create(OntologyHelper.PropertyInverseOf));
_graph.Retract(_graph.GetTriplesWithSubjectPredicate(_resource, inverseOf).ToList());
_graph.Retract(_graph.GetTriplesWithPredicateObject(inverseOf, _resource).ToList());
return ClearResourceProperty(OntologyHelper.PropertyInverseOf, true);
}
/// <summary>
/// Removes an inverse property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveInverseProperty(INode resource)
{
return RemoveResourceProperty(OntologyHelper.PropertyInverseOf, resource.CopyNode(_graph), true);
}
/// <summary>
/// Removes an inverse property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveInverseProperty(Uri resource)
{
return RemoveInverseProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Removes an inverse property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveInverseProperty(OntologyResource resource)
{
return RemoveInverseProperty(resource.Resource);
}
/// <summary>
/// Removes an inverse property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also removes this property as an inverse property of the given property.
/// </remarks>
public bool RemoveInverseProperty(OntologyProperty property)
{
bool a = RemoveInverseProperty(property.Resource);
bool b = property.RemoveInverseProperty(_resource);
return (a || b);
}
/// <summary>
/// Adds a sub-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddSubProperty(INode resource)
{
return AddResourceProperty(PropertyDerivedProperty, resource.CopyNode(_graph), false);
}
/// <summary>
/// Adds a sub-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddSubProperty(Uri resource)
{
return AddSubProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Adds a sub-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddSubProperty(OntologyResource resource)
{
return AddSubProperty(resource.Resource);
}
/// <summary>
/// Adds a sub-property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also adds this property as a super-property of the given property.
/// </remarks>
public bool AddSubProperty(OntologyProperty property)
{
bool a = AddSubProperty(property.Resource);
bool b = property.AddSuperProperty(_resource);
return (a || b);
}
/// <summary>
/// Clears all sub-properties of this property.
/// </summary>
/// <returns></returns>
public bool ClearSubProperties()
{
_graph.Retract(_graph.GetTriplesWithPredicateObject(_graph.CreateUriNode(UriFactory.Create(OntologyHelper.PropertySubPropertyOf)), _resource).ToList());
return ClearResourceProperty(PropertyDerivedProperty, false);
}
/// <summary>
/// Removes a sub-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveSubProperty(INode resource)
{
return RemoveResourceProperty(PropertyDerivedProperty, resource.CopyNode(_graph), false);
}
/// <summary>
/// Removes a sub-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveSubProperty(Uri resource)
{
return RemoveSubProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Removes a sub-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveSubProperty(OntologyResource resource)
{
return RemoveSubProperty(resource.Resource);
}
/// <summary>
/// Removes a sub-property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also removes this property as a super-property of the given property.
/// </remarks>
public bool RemoveSubProperty(OntologyProperty property)
{
bool a = RemoveSubProperty(property.Resource);
bool b = property.RemoveSuperProperty(_resource);
return (a || b);
}
/// <summary>
/// Adds a super-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddSuperProperty(INode resource)
{
return AddResourceProperty(OntologyHelper.PropertySubPropertyOf, resource.CopyNode(_graph), true);
}
/// <summary>
/// Adds a super-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddSuperProperty(Uri resource)
{
return AddSuperProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Adds a super-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool AddSuperProperty(OntologyResource resource)
{
return AddSuperProperty(resource.Resource);
}
/// <summary>
/// Adds a super-property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also adds this property as a sub-property of the given property.
/// </remarks>
public bool AddSuperProperty(OntologyProperty property)
{
bool a = AddSuperProperty(property.Resource);
bool b = property.AddSubProperty(_resource);
return (a || b);
}
/// <summary>
/// Removes all super-properties of this property.
/// </summary>
/// <returns></returns>
public bool ClearSuperProperties()
{
_graph.Retract(_graph.GetTriplesWithSubjectPredicate(_resource, _graph.CreateUriNode(UriFactory.Create(OntologyHelper.PropertySubPropertyOf))).ToList());
return ClearResourceProperty(OntologyHelper.PropertySubPropertyOf, true);
}
/// <summary>
/// Removes a super-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveSuperProperty(INode resource)
{
return RemoveResourceProperty(OntologyHelper.PropertySubPropertyOf, resource.CopyNode(_graph), true);
}
/// <summary>
/// Removes a super-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveSuperProperty(Uri resource)
{
return RemoveSuperProperty(_graph.CreateUriNode(resource));
}
/// <summary>
/// Removes a super-property for the property.
/// </summary>
/// <param name="resource">Resource.</param>
/// <returns></returns>
public bool RemoveSuperProperty(OntologyResource resource)
{
return RemoveSuperProperty(resource.Resource);
}
/// <summary>
/// Removes a super-property for the property.
/// </summary>
/// <param name="property">Property.</param>
/// <returns></returns>
/// <remarks>
/// This overload also removes this property as a sub-property of the given property.
/// </remarks>
public bool RemoveSuperProperty(OntologyProperty property)
{
bool a = RemoveSuperProperty(property.Resource);
bool b = property.RemoveSubProperty(_resource);
return (a || b);
}
/// <summary>
/// Gets all the Classes which are in the properties Domain.
/// </summary>
public IEnumerable<OntologyClass> Domains
{
get
{
return GetResourceProperty(OntologyHelper.PropertyDomain).Select(r => new OntologyClass(r, _graph));
}
}
/// <summary>
/// Gets all the Classes which are in this properties Range.
/// </summary>
public IEnumerable<OntologyClass> Ranges
{
get
{
return GetResourceProperty(OntologyHelper.PropertyRange).Select(r => new OntologyClass(r, _graph));
}
}
/// <summary>
/// Gets all the equivalent properties of this property.
/// </summary>
public IEnumerable<OntologyProperty> EquivalentProperties
{
get
{
return GetResourceProperty(OntologyHelper.PropertyEquivalentProperty).Select(r => new OntologyProperty(r, _graph));
}
}
/// <summary>
/// Gets the sub-properties of this property (both direct and indirect).
/// </summary>
public IEnumerable<OntologyProperty> SubProperties
{
get
{
return GetResourceProperty(PropertyDerivedProperty).Select(c => new OntologyProperty(c, _graph));
}
}
/// <summary>
/// Gets the direct sub-classes of this class.
/// </summary>
public IEnumerable<OntologyProperty> DirectSubProperties
{
get
{
return GetResourceProperty(PropertyDirectSubProperty).Select(p => new OntologyProperty(p, _graph));
}
}
/// <summary>
/// Gets the indirect sub-classes of this class.
/// </summary>
public IEnumerable<OntologyProperty> IndirectSubProperties
{
get
{
return (from c in GetResourceProperty(PropertyDerivedProperty)
where !GetResourceProperty(PropertyDirectSubProperty).Contains(c)
select new OntologyProperty(c, _graph));
}
}
/// <summary>
/// Gets the super-properties of this property (both direct and indirect).
/// </summary>
public IEnumerable<OntologyProperty> SuperProperties
{
get
{
return GetResourceProperty(OntologyHelper.PropertySubPropertyOf).Select(c => new OntologyProperty(c, _graph));
}
}
/// <summary>
/// Gets the direct super-properties of this property.
/// </summary>
public IEnumerable<OntologyProperty> DirectSuperProperties
{
get
{
return GetResourceProperty(PropertyDirectSuperProperty).Select(c => new OntologyProperty(c, _graph));
}
}
/// <summary>
/// Gets the indirect super-properties of this property.
/// </summary>
public IEnumerable<OntologyProperty> IndirectSuperProperty
{
get
{
return (from c in GetResourceProperty(OntologyHelper.PropertySubPropertyOf)
where !GetResourceProperty(PropertyDirectSuperProperty).Contains(c)
select new OntologyProperty(c, _graph));
}
}
/// <summary>
/// Gets whether this is a top property i.e. has no super properties defined.
/// </summary>
public bool IsTopProperty
{
get
{
return !SuperProperties.Any();
}
}
/// <summary>
/// Gets whether this is a btoom property i.e. has no sub properties defined.
/// </summary>
public bool IsBottomProperty
{
get
{
return !SubProperties.Any();
}
}
/// <summary>
/// Gets the Sibling properties of this property, if this property is the root of the ontology nothing is returned even if there are multiple root properties.
/// </summary>
public IEnumerable<OntologyProperty> Siblings
{
get
{
return GetResourceProperty(PropertyDirectSuperProperty)
.Select(p => new OntologyProperty(p, _graph))
.SelectMany(p => p.DirectSubProperties)
.Where(p => !p.Resource.Equals(_resource)).Distinct();
}
}
/// <summary>
/// Gets all the inverse properties of this property.
/// </summary>
public IEnumerable<OntologyProperty> InverseProperties
{
get
{
return GetResourceProperty(OntologyHelper.PropertyInverseOf).Select(r => new OntologyProperty(r, _graph));
}
}
/// <summary>
/// Gets all the resources that use this property.
/// </summary>
public IEnumerable<OntologyResource> UsedBy
{
get
{
return (from t in _graph.GetTriplesWithPredicate(_resource)
select t.Subject).Distinct().Select(r => new OntologyResource(r, _graph));
}
}
}
}