001: /******************************************************************
002: * File: RDFSCMPPreprocessHook.java
003: * Created by: Dave Reynolds
004: * Created on: 19-Jun-2003
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: RDFSCMPPreprocessHook.java,v 1.10 2008/01/02 12:06:17 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.impl;
010:
011: import com.hp.hpl.jena.reasoner.rulesys.*;
012: import com.hp.hpl.jena.reasoner.*;
013: import com.hp.hpl.jena.graph.*;
014: import com.hp.hpl.jena.vocabulary.RDF;
015: import com.hp.hpl.jena.vocabulary.RDFS;
016: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
017:
018: import java.util.*;
019:
020: /**
021: * A rule preprocessor that scans all supplied data looking for instances
022: * of container membership properties and adds those to the deductions set.
023: *
024: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
025: * @version $Revision: 1.10 $ on $Date: 2008/01/02 12:06:17 $
026: */
027: public class RDFSCMPPreprocessHook implements RulePreprocessHook {
028: protected static String memberPrefix = RDF.getURI() + "_";
029:
030: /**
031: * Invoke the preprocessing hook. This will be called during the
032: * preparation time of the hybrid reasoner.
033: * @param infGraph the inference graph which is being prepared,
034: * the hook code can use this to addDeductions or add additional
035: * rules (using addRuleDuringPrepare).
036: * @param dataFind the finder which packages up the raw data (both
037: * schema and data bind) and any cached transitive closures.
038: * @param inserts a temporary graph into which the hook should insert
039: * all new deductions that should be seen by the rules.
040: */
041: public void run(FBRuleInfGraph infGraph, Finder dataFind,
042: Graph inserts) {
043: ExtendedIterator it = dataFind.find(new TriplePattern(null,
044: null, null));
045: HashSet properties = new HashSet();
046: while (it.hasNext()) {
047: Triple triple = (Triple) it.next();
048: Node prop = triple.getPredicate();
049: if (prop.equals(RDF.Nodes.type)
050: && triple.getObject().equals(RDF.Nodes.Property)) {
051: prop = triple.getSubject();
052: }
053: if (properties.add(prop)) {
054: if (prop.getURI().startsWith(memberPrefix)) {
055: // A container property
056: inserts.add(new Triple(prop, RDF.Nodes.type,
057: RDFS.Nodes.ContainerMembershipProperty));
058: }
059: }
060: }
061: }
062:
063: /**
064: * Validate a triple add to see if it should reinvoke the hook. If so
065: * then the inference will be restarted at next prepare time. Incremental
066: * re-processing is not yet supported but in this case would be useful.
067: */
068: public boolean needsRerun(FBRuleInfGraph infGraph, Triple t) {
069: return (t.getPredicate().getURI().startsWith(memberPrefix));
070: }
071:
072: }
073:
074: /*
075: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
076: All rights reserved.
077:
078: Redistribution and use in source and binary forms, with or without
079: modification, are permitted provided that the following conditions
080: are met:
081:
082: 1. Redistributions of source code must retain the above copyright
083: notice, this list of conditions and the following disclaimer.
084:
085: 2. Redistributions in binary form must reproduce the above copyright
086: notice, this list of conditions and the following disclaimer in the
087: documentation and/or other materials provided with the distribution.
088:
089: 3. The name of the author may not be used to endorse or promote products
090: derived from this software without specific prior written permission.
091:
092: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
093: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
094: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
095: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
096: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
097: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
098: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
099: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
100: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
101: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102: */
|