You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ch...@apache.org on 2012/11/07 12:24:40 UTC
svn commit: r1406556 - in /jena/Scratch/Eyeball/trunk/src:
main/java/com/hp/hpl/jena/eyeball/inspectors/
main/java/com/hp/hpl/jena/eyeball/util/
main/java/com/hp/hpl/jena/eyeball/vocabulary/
test/java/com/hp/hpl/jena/eyeball/util/test/ test/java/com/hp...
Author: chrisdollin
Date: Wed Nov 7 11:24:39 2012
New Revision: 1406556
URL: http://svn.apache.org/viewvc?rev=1406556&view=rev
Log:
Making way clear for report-all form of inspection.
Modified:
jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/inspectors/PropertyInspector.java
jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/util/SetPropertiesFromString.java
jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/vocabulary/EyeballAssembling.java
jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/util/test/TestSetPropertiesFromString.java
jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/vocabulary/test/TestVocabulary.java
Modified: jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/inspectors/PropertyInspector.java
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/inspectors/PropertyInspector.java?rev=1406556&r1=1406555&r2=1406556&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/inspectors/PropertyInspector.java (original)
+++ jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/inspectors/PropertyInspector.java Wed Nov 7 11:24:39 2012
@@ -29,12 +29,20 @@ import com.hp.hpl.jena.vocabulary.*;
public class PropertyInspector extends InspectorBase implements Inspector
{
+ final boolean reportAll;
+
public PropertyInspector()
- { addBuiltinProperties(); }
+ { this( false ); }
public PropertyInspector( Resource root )
- { this(); }
+ { this( getBoolean( root, EYE.reportAll, false ) ); }
+ public PropertyInspector( boolean reportAll )
+ {
+ this.reportAll = false; // TODO: reportAll;
+ addBuiltinProperties();
+ }
+
public void begin( Report r, OntModel assume )
{
r.declareProperty( EYE.unknownPredicate );
@@ -44,8 +52,6 @@ public class PropertyInspector extends I
public void inspectModel( Report r, OntModel model )
{
addProperties( model );
-// for (Iterator<OntModel> models = model.listSubModels(); models.hasNext();)
-// addProperties( models.next() );
}
private void addBuiltinProperties()
@@ -76,7 +82,14 @@ public class PropertyInspector extends I
public void inspectStatement( Report r, Statement s )
{
Property predicate = s.getPredicate();
- if (seen.add( predicate ) && !knownProperty( predicate ))
- r.createItem( s ).addMainProperty( EYE.unknownPredicate, predicate );
+ if (!knownProperty( predicate ))
+ if (seen.add( predicate ) || reportAll)
+ r.createItem( s ).addMainProperty( EYE.unknownPredicate, predicate );
}
+
+ private static boolean getBoolean( Resource root, Property which, boolean ifAbsent )
+ {
+ Statement s = root.getProperty( which );
+ return s == null ? ifAbsent : s.getBoolean();
+ }
}
Modified: jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/util/SetPropertiesFromString.java
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/util/SetPropertiesFromString.java?rev=1406556&r1=1406555&r2=1406556&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/util/SetPropertiesFromString.java (original)
+++ jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/util/SetPropertiesFromString.java Wed Nov 7 11:24:39 2012
@@ -21,14 +21,14 @@ package com.hp.hpl.jena.eyeball.util;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.shared.PrefixMapping;
/**
A utility class to add statements to a model (supplied to its constructor)
from a template string of the form `subject.predicate=object`. The subject,
- predicate, and object are all in NodeCreateUtils syntax (at this time).
+ predicate, and object are all in a simple ad-hoc syntax (at this time).
- @author kers
*/
public class SetPropertiesFromString
{
@@ -38,22 +38,48 @@ public class SetPropertiesFromString
public SetPropertiesFromString( Model m )
{ this.m = m; this.pm = m.getGraph().getPrefixMapping(); }
- public void set( String string )
+ /**
+ Add a statement to <code>m</code> derived from the string
+ <code>setBy</code> which must have the form S.P=O. Each of S, P, and O
+ must be one of the forms:
+
+ <ul>
+ <li>
+ decimal digits, representing a literal node with that integer value.
+ <li>
+ true or false, representing a literal node with that boolean value.
+ <li>
+ 'characters', representing a plain string literal with that
+ quoted value.
+ <li>
+ p:l, representing a resource with namespace given by the
+ prefix value p and localname l.
+ <li>
+ otherwise, the same as p:l with no p (so, using the default prefix).
+ </ul>
+ */
+ public void set( String setBy )
{
- int dotPos = string.indexOf( '.' );
- int eqPos = string.indexOf( '=', dotPos );
- String S = string.substring( 0, dotPos );
- String P = string.substring( dotPos + 1, eqPos );
- String O = string.substring( eqPos + 1 );
+ int dotPos = setBy.indexOf( '.' );
+ int eqPos = setBy.indexOf( '=', dotPos );
+ String S = setBy.substring( 0, dotPos );
+ String P = setBy.substring( dotPos + 1, eqPos );
+ String O = setBy.substring( eqPos + 1 );
m.getGraph().add( Triple.create( createNode( S ), createNode( P ), createNode( O ) ) );
}
+ static final Node TRUE = ResourceFactory.createTypedLiteral( true ).asNode();
+
+ static final Node FALSE = ResourceFactory.createTypedLiteral( false ).asNode();
+
private Node createNode( String s )
{
if (s.equals("")) s = "''";
char ch = s.charAt(0);
//
if (Character.isDigit( ch )) return createInteger(s);
+ if (s.equals("true")) return TRUE;
+ if (s.equals("false")) return FALSE;
if (ch == '\'') return createLiteral(s);
if (s.indexOf(':') < 0) s = ":" + s;
return Node.createURI( pm.expandPrefix( s ) );
Modified: jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/vocabulary/EyeballAssembling.java
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/vocabulary/EyeballAssembling.java?rev=1406556&r1=1406555&r2=1406556&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/vocabulary/EyeballAssembling.java (original)
+++ jena/Scratch/Eyeball/trunk/src/main/java/com/hp/hpl/jena/eyeball/vocabulary/EyeballAssembling.java Wed Nov 7 11:24:39 2012
@@ -81,4 +81,6 @@ public interface EyeballAssembling exten
public static final Property useFormat = R.p( "useFormat" );
public static final Property labels = R.p( "labels" );
+
+ public static final Property reportAll = R.p( "reportAll" );
}
Modified: jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/util/test/TestSetPropertiesFromString.java
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/util/test/TestSetPropertiesFromString.java?rev=1406556&r1=1406555&r2=1406556&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/util/test/TestSetPropertiesFromString.java (original)
+++ jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/util/test/TestSetPropertiesFromString.java Wed Nov 7 11:24:39 2012
@@ -52,6 +52,12 @@ import com.hp.hpl.jena.rdf.model.Model;
testSettingStringAddsModel( EYE.getURI(), "eye:a eye:b 'hello'", "a.b='hello'" );
}
+ @Test public void testSettingAllowsBooleans()
+ {
+ testSettingStringAddsModel( EYE.getURI(), "eye:a eye:b 'true'xsd:boolean", "a.b=true" );
+ testSettingStringAddsModel( EYE.getURI(), "eye:a eye:b 'false'xsd:boolean", "a.b=false" );
+ }
+
private void testSettingStringAddsModel( String emptyPrefix, String expected, String setting )
{
Model m = model();
Modified: jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/vocabulary/test/TestVocabulary.java
URL: http://svn.apache.org/viewvc/jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/vocabulary/test/TestVocabulary.java?rev=1406556&r1=1406555&r2=1406556&view=diff
==============================================================================
--- jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/vocabulary/test/TestVocabulary.java (original)
+++ jena/Scratch/Eyeball/trunk/src/test/java/com/hp/hpl/jena/eyeball/vocabulary/test/TestVocabulary.java Wed Nov 7 11:24:39 2012
@@ -53,6 +53,7 @@ import com.hp.hpl.jena.vocabulary.RDFS;
assertEyeballURIEquals( "prohibit", EyeballAssembling.prohibit );
assertEyeballURIEquals( "sparql", EyeballAssembling.sparql );
assertEyeballURIEquals( "message", EyeballAssembling.message );
+ assertEyeballURIEquals( "reportAll", EyeballAssembling.reportAll );
}
private void assertEyeballURIEquals( String local, Resource r )