Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }