예제 #1
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        private void Validate()
        {
            //Validation 1. Each rdfs:domain triple MUST have a corresponding rdfs:type
            //triple such that subject(rdfs:domain triple) = subject(rdfs:type triple).
            //The object of rdfs:type triple MUST be rdfs:Property.
            //Validation 2. Each rdfs:domain triple MUST have a corresponding rdfs:type
            //triple such that object(rdfs:domain triple) = subject(rdfs:type triple).
            //The object of the rdfs:type triple MUST be rdfs:Class.
            foreach (Triple triple in DomainTriples)
            {
                if (PropertyTriples.Where(tuple =>
                                          tuple.TripleSubject == triple.TripleSubject).Count() == 0)
                {
                    throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                          DataModellingResources.MsgDomainInterpreterDomainTripleSubjectNotDefined,
                                                          triple.ToString()));
                }

                if (ClassTriples.Where(tuple =>
                                       tuple.TripleSubject == triple.TripleObject).Count() == 0)
                {
                    throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                          DataModellingResources.MsgDomainInterpreterDomainTripleObjectNotDefined,
                                                          triple.ToString()));
                }
            }

            //Validation 3. Each rdfs:range triple MUST have a corresponding rdf:type
            //triple with the same subject. The object of rdf:type triple MUST be rdfs:Property.
            //Validation 4. Each rdfs:range triple MAY have a corresponding rdfs:type triple
            //such that object(rdfs:range triple) = subject(rdfs:type triple). If there exists
            //such an rdfs:type triple, then the object of the rdfs:type triple MUST be
            //rdfs:Class. Otherwise, the object of rdfs:range SHOULD be treated as a datatype
            //reference, XSD or derived.
            foreach (Triple triple in RangeTriples)
            {
                if (PropertyTriples.Where(tuple =>
                                          tuple.TripleSubject == triple.TripleSubject).Count() == 0)
                {
                    throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                          DataModellingResources.MsgDomainInterpreterRangeTripleSubjectNotDefined,
                                                          triple.ToString()));
                }

                if (ClassTriples.
                    Where(tuple => tuple.TripleSubject == triple.TripleObject).Count() == 0
                    &&
                    (Context.XsdDataTypeCollection.
                     Where(tuple => tuple.Name == triple.TripleObject).Count() == 0)
                    )
                {
                    throw new RdfsException(string.Format(CultureInfo.InvariantCulture,
                                                          DataModellingResources.MsgDomainInterpreterRangeTripleObjectNotDefined,
                                                          triple.ToString()));
                }
            }
        }
예제 #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);
                        }
                    }
                }
            }
        }