1

I am trying to write a SPIN-Rule that will count the number of incoming references and set this number as a property value. E.g., count number of Issues that occurred on a particular machine. Therefore I need to count the number of incoming references of type rdfs:occuredOn (domain: Issue, range: Machine).

CONSTRUCT {
?machine rdfs:numberOfIssues ?n .
}

WHERE {
?machine a ex:Machine .
?issue a ex:Issue .
?issue ?r ?machine .
(COUNT(?r) AS ?n) //Error
}       

Thank you in advance!

4

1 回答 1

7

GroupGraphPattern允许,即您必须在子句中使用子SELECT查询:WHERE

CONSTRUCT 
  { 
    ?machine rdfs:numberOfIssues ?n .
  }
WHERE
  { { SELECT  ?machine (COUNT(?r) AS ?n)
      WHERE
        { ?machine  a  owl:Machine .
          ?issue    a  owl:Issue ;
                    ?r        ?machine
        }
      GROUP BY ?machine
    }
  } 

请注意,您永远不应该为您的域本体使用内置命名空间/前缀(例如owl:rdfs:rdf:xsd:等)!

于 2017-08-27T12:17:18.763 回答