Exemplo n.º 1
0
        /// <summary>
        /// Checks if the skos:narrower/skos:narrowerTransitive/skos:narrowMatch relation can be added to the given aConcept with the given bConcept
        /// </summary>
        internal static Boolean CheckNarrowerRelation(RDFSKOSConceptScheme conceptScheme,
                                                      RDFSKOSConcept aConcept,
                                                      RDFSKOSConcept bConcept)
        {
            var canAddNarrowerRel = false;

            //Avoid clash with hierarchical relations
            canAddNarrowerRel = !conceptScheme.CheckHasBroaderConcept(aConcept, bConcept);

            //Avoid clash with associative relations
            if (canAddNarrowerRel)
            {
                canAddNarrowerRel = !conceptScheme.CheckHasRelatedConcept(aConcept, bConcept);
            }

            //Avoid clash with mapping relations
            if (canAddNarrowerRel)
            {
                canAddNarrowerRel = (!conceptScheme.CheckHasBroadMatchConcept(aConcept, bConcept) &&
                                     !conceptScheme.CheckHasCloseMatchConcept(aConcept, bConcept) &&
                                     !conceptScheme.CheckHasExactMatchConcept(aConcept, bConcept) &&
                                     !conceptScheme.CheckHasRelatedMatchConcept(aConcept, bConcept));
            }

            return(canAddNarrowerRel);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds the given concept to the conceptScheme as top concept of the hierarchy
 /// </summary>
 public static RDFSKOSConceptScheme AddTopConceptRelation(this RDFSKOSConceptScheme conceptScheme,
                                                          RDFSKOSConcept concept)
 {
     if (conceptScheme != null && concept != null && !conceptScheme.Equals(concept))
     {
         //Add skos:hasTopConcept relation to the scheme
         conceptScheme.Relations.TopConcept.AddEntry(new RDFOntologyTaxonomyEntry(conceptScheme, RDFVocabulary.SKOS.HAS_TOP_CONCEPT.ToRDFOntologyObjectProperty(), concept));
     }
     return(conceptScheme);
 }
 /// <summary>
 /// Adds the given concept to the collection
 /// </summary>
 public RDFSKOSOrderedCollection AddConcept(RDFSKOSConcept concept)
 {
     if (concept != null)
     {
         if (!this.Concepts.ContainsKey(concept.PatternMemberID))
         {
             this.Concepts.Add(concept.PatternMemberID, new Tuple <int, RDFSKOSConcept>(this.ConceptsSequentialCounter++, concept));
         }
     }
     return(this);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Adds the given literal as 'skos:definition' annotation of the given concept within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddDefinitionAnnotation(this RDFSKOSConceptScheme conceptScheme,
                                                            RDFSKOSConcept concept,
                                                            RDFOntologyLiteral literal)
 {
     if (conceptScheme != null && concept != null && literal != null)
     {
         //Add definition annotation to the scheme
         conceptScheme.Annotations.Definition.AddEntry(new RDFOntologyTaxonomyEntry(concept, RDFVocabulary.SKOS.DEFINITION.ToRDFOntologyAnnotationProperty(), literal));
     }
     return(conceptScheme);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds the given concept to the collection
 /// </summary>
 public RDFSKOSCollection AddConcept(RDFSKOSConcept concept)
 {
     if (concept != null)
     {
         if (!this.Concepts.ContainsKey(concept.PatternMemberID))
         {
             this.Concepts.Add(concept.PatternMemberID, concept);
         }
     }
     return(this);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Adds the given literal as 'skos:scopeNote' annotation of the given concept within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddScopeNoteAnnotation(this RDFSKOSConceptScheme conceptScheme,
                                                           RDFSKOSConcept concept,
                                                           RDFOntologyLiteral literal)
 {
     if (conceptScheme != null && concept != null && literal != null)
     {
         //Add scopeNote annotation to the scheme
         conceptScheme.Annotations.ScopeNote.AddEntry(new RDFOntologyTaxonomyEntry(concept, RDFVocabulary.SKOS.SCOPE_NOTE.ToRDFOntologyAnnotationProperty(), literal));
     }
     return(conceptScheme);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Removes the given concept from the collection
 /// </summary>
 public RDFSKOSCollection RemoveConcept(RDFSKOSConcept concept)
 {
     if (concept != null)
     {
         if (this.Concepts.ContainsKey(concept.PatternMemberID))
         {
             this.Concepts.Remove(concept.PatternMemberID);
         }
     }
     return(this);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Adds the given notation to the given concept within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddNotationRelation(this RDFSKOSConceptScheme conceptScheme,
                                                        RDFSKOSConcept concept,
                                                        RDFOntologyLiteral notationLiteral)
 {
     if (conceptScheme != null && concept != null && notationLiteral != null)
     {
         //Add skos:Notation relation to the scheme
         conceptScheme.Relations.Notation.AddEntry(new RDFOntologyTaxonomyEntry(concept, RDFVocabulary.SKOS.NOTATION.ToRDFOntologyDatatypeProperty(), notationLiteral));
     }
     return(conceptScheme);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Adds the given literal as 'skos:example' annotation of the given concept within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddExampleAnnotation(this RDFSKOSConceptScheme conceptScheme,
                                                         RDFSKOSConcept concept,
                                                         RDFOntologyLiteral literal)
 {
     if (conceptScheme != null && concept != null && literal != null)
     {
         //Add example annotation to the scheme
         conceptScheme.Annotations.Example.AddEntry(new RDFOntologyTaxonomyEntry(concept, RDFVocabulary.SKOS.EXAMPLE.ToRDFOntologyAnnotationProperty(), literal));
     }
     return(conceptScheme);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Adds a 'skos:semanticRelation' relation between the given concepts within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddSemanticRelation(this RDFSKOSConceptScheme conceptScheme,
                                                        RDFSKOSConcept aConcept,
                                                        RDFSKOSConcept bConcept)
 {
     if (conceptScheme != null && aConcept != null && bConcept != null && !aConcept.Equals(bConcept))
     {
         //Add skos:semanticRelation relation to the scheme
         conceptScheme.Relations.SemanticRelation.AddEntry(new RDFOntologyTaxonomyEntry(aConcept, RDFVocabulary.SKOS.SEMANTIC_RELATION.ToRDFOntologyObjectProperty(), bConcept));
     }
     return(conceptScheme);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Enlists the skos:exactMatch concepts of the given concept within the given scheme
        /// </summary>
        public static RDFSKOSConceptScheme GetExactMatchConceptsOf(this RDFSKOSConceptScheme conceptScheme,
                                                                   RDFSKOSConcept concept)
        {
            var result = new RDFSKOSConceptScheme((RDFResource)conceptScheme.Value);

            if (concept != null && conceptScheme != null)
            {
                result = conceptScheme.GetExactMatchConceptsOfInternal(concept, null)
                         .RemoveConcept(concept);                //Safety deletion
            }
            return(result);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Adds a 'skos:narrowMatch' relation between the given concepts within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddNarrowMatchRelation(this RDFSKOSConceptScheme conceptScheme,
                                                           RDFSKOSConcept aConcept,
                                                           RDFSKOSConcept bConcept)
 {
     if (conceptScheme != null && aConcept != null && bConcept != null && !aConcept.Equals(bConcept))
     {
         if (RDFSKOSChecker.CheckNarrowerRelation(conceptScheme, aConcept, bConcept))
         {
             //Add skos:narrowMatch relation to the scheme
             conceptScheme.Relations.NarrowMatch.AddEntry(new RDFOntologyTaxonomyEntry(aConcept, RDFVocabulary.SKOS.NARROW_MATCH.ToRDFOntologyObjectProperty(), bConcept));
         }
     }
     return(conceptScheme);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Adds a 'skos:broaderTransitive' relation between the given concepts within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddBroaderTransitiveRelation(this RDFSKOSConceptScheme conceptScheme,
                                                                 RDFSKOSConcept aConcept,
                                                                 RDFSKOSConcept bConcept)
 {
     if (conceptScheme != null && aConcept != null && bConcept != null && !aConcept.Equals(bConcept))
     {
         if (RDFSKOSChecker.CheckBroaderRelation(conceptScheme, aConcept, bConcept))
         {
             //Add skos:broaderTransitive relation to the scheme
             conceptScheme.Relations.BroaderTransitive.AddEntry(new RDFOntologyTaxonomyEntry(aConcept, RDFVocabulary.SKOS.BROADER_TRANSITIVE.ToRDFOntologyObjectProperty(), bConcept));
         }
     }
     return(conceptScheme);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Enlists the skos:closeMatch concepts of the given concept within the given scheme
        /// </summary>
        public static RDFSKOSConceptScheme GetCloseMatchConceptsOf(this RDFSKOSConceptScheme conceptScheme,
                                                                   RDFSKOSConcept concept)
        {
            var result = new RDFSKOSConceptScheme((RDFResource)conceptScheme.Value);

            if (concept != null && conceptScheme != null)
            {
                foreach (var closeMatchConcept in conceptScheme.Relations.CloseMatch.SelectEntriesBySubject(concept))
                {
                    result.AddConcept((RDFSKOSConcept)closeMatchConcept.TaxonomyObject);
                }
            }
            return(result);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Adds a 'skos:exactMatch' relation between the given concepts within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddExactMatchRelation(this RDFSKOSConceptScheme conceptScheme,
                                                          RDFSKOSConcept aConcept,
                                                          RDFSKOSConcept bConcept)
 {
     if (conceptScheme != null && aConcept != null && bConcept != null && !aConcept.Equals(bConcept))
     {
         if (RDFSKOSChecker.CheckCloseOrExactMatchRelation(conceptScheme, aConcept, bConcept))
         {
             //Add skos:exactMatch relation to the scheme
             conceptScheme.Relations.ExactMatch.AddEntry(new RDFOntologyTaxonomyEntry(aConcept, RDFVocabulary.SKOS.EXACT_MATCH.ToRDFOntologyObjectProperty(), bConcept));
             conceptScheme.Relations.ExactMatch.AddEntry(new RDFOntologyTaxonomyEntry(bConcept, RDFVocabulary.SKOS.EXACT_MATCH.ToRDFOntologyObjectProperty(), aConcept)
                                                         .SetInference(RDFSemanticsEnums.RDFOntologyInferenceType.API));
         }
     }
     return(conceptScheme);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Adds a 'skos:related' relation between the given concepts within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddRelatedRelation(this RDFSKOSConceptScheme conceptScheme,
                                                       RDFSKOSConcept aConcept,
                                                       RDFSKOSConcept bConcept)
 {
     if (conceptScheme != null && aConcept != null && bConcept != null && !aConcept.Equals(bConcept))
     {
         if (RDFSKOSChecker.CheckRelatedRelation(conceptScheme, aConcept, bConcept))
         {
             //Add skos:related relations to the scheme
             conceptScheme.Relations.Related.AddEntry(new RDFOntologyTaxonomyEntry(aConcept, RDFVocabulary.SKOS.RELATED.ToRDFOntologyObjectProperty(), bConcept));
             conceptScheme.Relations.Related.AddEntry(new RDFOntologyTaxonomyEntry(bConcept, RDFVocabulary.SKOS.RELATED.ToRDFOntologyObjectProperty(), aConcept)
                                                      .SetInference(RDFSemanticsEnums.RDFOntologyInferenceType.API));
         }
     }
     return(conceptScheme);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Adds the given literal as preferred label annotation of the given concept within the conceptScheme
 /// </summary>
 public static RDFSKOSConceptScheme AddPrefLabelAnnotation(this RDFSKOSConceptScheme conceptScheme,
                                                           RDFSKOSConcept concept,
                                                           RDFOntologyLiteral prefLabelLiteral)
 {
     if (conceptScheme != null && concept != null && prefLabelLiteral != null)
     {
         //Only plain literals are allowed as skos:prefLabel annotations
         if (prefLabelLiteral.Value is RDFPlainLiteral)
         {
             if (RDFSKOSChecker.CheckPrefLabel(conceptScheme, concept, prefLabelLiteral))
             {
                 //Add prefLabel annotation
                 conceptScheme.Annotations.PrefLabel.AddEntry(new RDFOntologyTaxonomyEntry(concept, RDFVocabulary.SKOS.PREF_LABEL.ToRDFOntologyAnnotationProperty(), prefLabelLiteral));
             }
         }
     }
     return(conceptScheme);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Adds the "concept -> skos:hiddenLabel -> hiddenLabelLiteral" annotation to the concept scheme
 /// </summary>
 public static RDFSKOSConceptScheme AddHiddenLabelAnnotation(this RDFSKOSConceptScheme conceptScheme,
                                                             RDFSKOSConcept concept,
                                                             RDFOntologyLiteral hiddenLabelLiteral)
 {
     if (conceptScheme != null && concept != null && hiddenLabelLiteral != null)
     {
         //Only plain literals are allowed as skos:hiddenLabel annotations
         if (hiddenLabelLiteral.Value is RDFPlainLiteral)
         {
             if (RDFSKOSChecker.CheckHiddenLabel(conceptScheme, concept, hiddenLabelLiteral))
             {
                 //Add hiddenLabel annotation
                 conceptScheme.Annotations.HiddenLabel.AddEntry(new RDFOntologyTaxonomyEntry(concept, RDFVocabulary.SKOS.HIDDEN_LABEL.ToRDFOntologyAnnotationProperty(), hiddenLabelLiteral));
             }
         }
     }
     return(conceptScheme);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Enlists the narrower/narrowerTransitive concepts of the given concept within the given scheme
        /// </summary>
        public static RDFSKOSConceptScheme GetNarrowerConceptsOf(this RDFSKOSConceptScheme conceptScheme,
                                                                 RDFSKOSConcept concept)
        {
            var result = new RDFSKOSConceptScheme((RDFResource)conceptScheme.Value);

            if (concept != null && conceptScheme != null)
            {
                //Get skos:narrower concepts
                foreach (var narrowerConcept in conceptScheme.Relations.Narrower.SelectEntriesBySubject(concept))
                {
                    result.AddConcept((RDFSKOSConcept)narrowerConcept.TaxonomyObject);
                }

                //Get skos:narrowerTransitive concepts
                result = result.UnionWith(conceptScheme.GetNarrowerConceptsOfInternal(concept, null))
                         .RemoveConcept(concept);         //Safety deletion
            }
            return(result);
        }
 /// <summary>
 /// Builds a scheme lens for the given concept on the given scheme
 /// </summary>
 public RDFSKOSConceptSchemeLens(RDFSKOSConcept concept, RDFSKOSConceptScheme scheme)
 {
     if (concept != null)
     {
         if (scheme != null)
         {
             this.Concept = concept;
             this.Scheme  = scheme;
         }
         else
         {
             throw new RDFSemanticsException("Cannot create scheme lens because given \"scheme\" parameter is null");
         }
     }
     else
     {
         throw new RDFSemanticsException("Cannot create scheme lens because given \"concept\" parameter is null");
     }
 }
        /// <summary>
        /// Checks if the skos:closeMatch/skos:exactMatch relation can be added to the given aConcept with the given bConcept
        /// </summary>
        internal static bool CheckCloseOrExactMatchRelation(RDFSKOSConceptScheme conceptScheme,
                                                            RDFSKOSConcept aConcept,
                                                            RDFSKOSConcept bConcept)
        {
            var canAddCloseOrExactMatchRel = false;

            //Avoid clash with hierarchical relations
            canAddCloseOrExactMatchRel = (!conceptScheme.CheckHasBroaderConcept(aConcept, bConcept) &&
                                          !conceptScheme.CheckHasNarrowerConcept(aConcept, bConcept));

            //Avoid clash with mapping relations
            if (canAddCloseOrExactMatchRel)
            {
                canAddCloseOrExactMatchRel = (!conceptScheme.CheckHasBroadMatchConcept(aConcept, bConcept) &&
                                              !conceptScheme.CheckHasNarrowMatchConcept(aConcept, bConcept) &&
                                              !conceptScheme.CheckHasRelatedMatchConcept(aConcept, bConcept));
            }

            return(canAddCloseOrExactMatchRel);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Adds the given label as hidden label of the given concept within the conceptScheme
        /// </summary>
        public static RDFSKOSConceptScheme AddHiddenLabelRelation(this RDFSKOSConceptScheme conceptScheme,
                                                                  RDFSKOSConcept concept,
                                                                  RDFSKOSLabel label,
                                                                  RDFOntologyLiteral hiddenLabelLiteral)
        {
            if (conceptScheme != null && concept != null && label != null && hiddenLabelLiteral != null)
            {
                //Only plain literals are allowed as skosxl:hiddenLabel assertions
                if (hiddenLabelLiteral.Value is RDFPlainLiteral)
                {
                    if (RDFSKOSChecker.CheckHiddenLabel(conceptScheme, concept, hiddenLabelLiteral))
                    {
                        //Add hiddenLabel relation
                        conceptScheme.Relations.HiddenLabel.AddEntry(new RDFOntologyTaxonomyEntry(concept, RDFVocabulary.SKOS.SKOSXL.HIDDEN_LABEL.ToRDFOntologyObjectProperty(), label));

                        //Add literalForm relation
                        conceptScheme.Relations.LiteralForm.AddEntry(new RDFOntologyTaxonomyEntry(label, RDFVocabulary.SKOS.SKOSXL.LITERAL_FORM.ToRDFOntologyDatatypeProperty(), hiddenLabelLiteral));
                    }
                }
            }
            return(conceptScheme);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Subsumes the "skos:narrowerTransitive" taxonomy to discover direct and indirect narrower concepts of the given scheme
        /// </summary>
        internal static RDFSKOSConceptScheme GetNarrowerConceptsOfInternal(this RDFSKOSConceptScheme conceptScheme,
                                                                           RDFSKOSConcept concept,
                                                                           Dictionary <long, RDFSKOSConcept> visitContext)
        {
            var result = new RDFSKOSConceptScheme((RDFResource)conceptScheme.Value);

            #region visitContext
            if (visitContext == null)
            {
                visitContext = new Dictionary <long, RDFSKOSConcept>()
                {
                    { concept.PatternMemberID, concept }
                };
            }
            else
            {
                if (!visitContext.ContainsKey(concept.PatternMemberID))
                {
                    visitContext.Add(concept.PatternMemberID, concept);
                }
                else
                {
                    return(result);
                }
            }
            #endregion

            //Transitivity of "skos:narrowerTransitive" taxonomy:
            //((A SKOS:NARROWERTRANSITIVE B)  &&  (B SKOS:NARROWERTRANSITIVE C))  =>  (A SKOS:NARROWERTRANSITIVE C)
            foreach (var nt in conceptScheme.Relations.NarrowerTransitive.SelectEntriesBySubject(concept))
            {
                result.AddConcept((RDFSKOSConcept)nt.TaxonomyObject);

                //Exploit skos:narrowerTransitive taxonomy
                result = result.UnionWith(conceptScheme.GetNarrowerConceptsOfInternal((RDFSKOSConcept)nt.TaxonomyObject, visitContext));
            }

            return(result);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Subsumes the "skos:exactMatch" taxonomy to discover direct and indirect exactmatches of the given concept
        /// </summary>
        internal static RDFSKOSConceptScheme GetExactMatchConceptsOfInternal(this RDFSKOSConceptScheme conceptScheme,
                                                                             RDFSKOSConcept concept,
                                                                             Dictionary <long, RDFSKOSConcept> visitContext)
        {
            var result = new RDFSKOSConceptScheme((RDFResource)conceptScheme.Value);

            #region visitContext
            if (visitContext == null)
            {
                visitContext = new Dictionary <long, RDFSKOSConcept>()
                {
                    { concept.PatternMemberID, concept }
                };
            }
            else
            {
                if (!visitContext.ContainsKey(concept.PatternMemberID))
                {
                    visitContext.Add(concept.PatternMemberID, concept);
                }
                else
                {
                    return(result);
                }
            }
            #endregion

            // Transitivity of "skos:exactMatch" taxonomy:
            //((A SKOS:EXACTMATCH B)  &&  (B SKOS:EXACTMATCH C))  =>  (A SKOS:EXACTMATCH C)
            foreach (var em in conceptScheme.Relations.ExactMatch.SelectEntriesBySubject(concept))
            {
                result.AddConcept((RDFSKOSConcept)em.TaxonomyObject);
                result = result.UnionWith(conceptScheme.GetExactMatchConceptsOfInternal((RDFSKOSConcept)em.TaxonomyObject, visitContext));
            }

            return(result);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Checks if the given aConcept skos:exactMatch the given bConcept within the given scheme
 /// </summary>
 public static bool CheckHasExactMatchConcept(this RDFSKOSConceptScheme conceptScheme,
                                              RDFSKOSConcept aConcept,
                                              RDFSKOSConcept bConcept)
 {
     return(aConcept != null && bConcept != null && conceptScheme != null ? conceptScheme.GetExactMatchConceptsOf(aConcept).Concepts.ContainsKey(bConcept.PatternMemberID) : false);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Checks if the given aConcept has related concept the given bConcept within the given scheme
 /// </summary>
 public static bool CheckHasRelatedConcept(this RDFSKOSConceptScheme data,
                                           RDFSKOSConcept aConcept,
                                           RDFSKOSConcept bConcept)
 {
     return(aConcept != null && bConcept != null && data != null ? data.GetRelatedConceptsOf(aConcept).Concepts.ContainsKey(bConcept.PatternMemberID) : false);
 }