/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }