Example #1
0
        /// <summary>
        /// Enlists the broader/broaderTransitive concepts of the given concept within the given scheme
        /// </summary>
        public static RDFSKOSConceptScheme GetBroaderConceptsOf(this RDFSKOSConceptScheme conceptScheme,
                                                                RDFSKOSConcept concept)
        {
            var result = new RDFSKOSConceptScheme((RDFResource)conceptScheme.Value);

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

                //Get skos:broaderTransitive concepts
                result = result.UnionWith(conceptScheme.GetBroaderConceptsOfInternal(concept, null))
                         .RemoveConcept(concept);               //Safety deletion
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Subsumes the "skos:broaderTransitive" taxonomy to discover direct and indirect broader concepts of the given scheme
        /// </summary>
        internal static RDFSKOSConceptScheme GetBroaderConceptsOfInternal(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:broaderTransitive" taxonomy:
            //((A SKOS:BROADERTRANSITIVE B)  &&  (B SKOS:BROADERTRANSITIVE C))  =>  (A SKOS:BROADERTRANSITIVE C)
            foreach (var bt in conceptScheme.Relations.BroaderTransitive.SelectEntriesBySubject(concept))
            {
                result.AddConcept((RDFSKOSConcept)bt.TaxonomyObject);

                //Exploit skos:broaderTransitive taxonomy
                result = result.UnionWith(conceptScheme.GetBroaderConceptsOfInternal((RDFSKOSConcept)bt.TaxonomyObject, visitContext));
            }

            return(result);
        }