Example #1
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);
        }
Example #2
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);
        }