Beispiel #1
0
        /// <summary>
        /// Interprets Domain and Range triples.
        /// </summary>
        /// <param name="dataModelModule">Instance of DataModelModule class to be updated.</param>
        internal override void Interpret(DataModelModule dataModelModule)
        {
            // Validate domain and range triple rules.
            Validate();

            foreach (Triple triple in PropertyTriples)
            {
                //Get range and domain triples.
                Triple rangeTriple = RangeTriples.
                                     Where(tuple => tuple.TripleSubject == triple.TripleSubject).First();
                Triple domainTriple = DomainTriples.
                                      Where(tuple => tuple.TripleSubject == triple.TripleSubject).First();

                //Add property.
                if (IsScalarProperty(rangeTriple.TripleObject as RDFUriReference))
                {
                    AddScalarProperty(domainTriple, rangeTriple, dataModelModule);
                }
                else
                {
                    AddNavigationProperty(domainTriple, rangeTriple, dataModelModule);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Validates the property triples.
        /// </summary>
        private void ValidatePropertyTriples()
        {
            //Validation 3. In ‘Strict’ mode, the importer MUST raise errors if there is a property
            //defined in the graph, but the count of rdf:domain and rdf:range triples for
            //this property present in the graph is not exactly one.
            foreach (Triple triple in PropertyTriples.ToList())
            {
                List <Triple> propDomains = DomainTriples.Where(tuple =>
                                                                tuple.TripleSubject == triple.TripleSubject).ToList();
                List <Triple> propRanges = RangeTriples.Where(tuple =>
                                                              tuple.TripleSubject == triple.TripleSubject).ToList();

                if (Context.ExecutionMode == ExecutionMode.Strict)
                {
                    if (propDomains.Count() > 1)
                    {
                        throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                              DataModellingResources.MsgTypeInterpreterMoreDomains,
                                                              triple.ToString()));
                    }

                    if (propRanges.Count() > 1)
                    {
                        throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                              DataModellingResources.MsgTypeInterpreterMoreRanges,
                                                              triple.ToString()));
                    }

                    if (propDomains.Count() == 0)
                    {
                        throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                              DataModellingResources.MsgTypeInterpreterNoDomains,
                                                              triple.ToString()));
                    }

                    if (propRanges.Count() == 0)
                    {
                        throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                              DataModellingResources.MsgTypeInterpreterNoRanges,
                                                              triple.ToString()));
                    }
                }
                else
                {
                    //In ‘Loose’ mode, if the rdf:domain triple for the property is not present,
                    //the importer removes the rdf:type triple along with all the rdf:range
                    //triples in the graph.
                    if (propDomains.Count() != 1 || propRanges.Count() != 1)
                    {
                        Context.Graph.Remove(triple);
                        foreach (Triple domainTriple in propDomains)
                        {
                            Context.Graph.Remove(domainTriple);
                        }
                        foreach (Triple rangeTriple in propRanges)
                        {
                            Context.Graph.Remove(rangeTriple);
                        }
                    }
                }
            }
        }