public void testCreatePropertyStrangeURITwoArgs() { final String local = "_345"; final Property p = model.createProperty(RDF.getURI(), local); Assert.assertEquals(RDF.getURI(), p.getNameSpace()); Assert.assertEquals(local, p.getLocalName()); Assert.assertEquals(RDF.getURI() + local, p.getURI()); }
public void testCreatePropertyStrangeURI() { final String uri = RDF.getURI() + "_345"; final Property p = model.createProperty(uri); Assert.assertEquals(RDF.getURI(), p.getNameSpace()); Assert.assertEquals("_345", p.getLocalName()); Assert.assertEquals(uri, p.getURI()); }
@Override public boolean accept(OntClass cls) { if (!cls.isAnon()) { return cls.getURI().startsWith(RDF.getURI()); } return false; }
public class WriterConst { // See INDENT_PREDICATE // public static final int MIN_SUBJECT = 4 ; /** Minimum width of the predicate columns. */ public static final int MIN_PREDICATE = 4; /** Subjects longer than this have a NL after them. */ public static final int LONG_SUBJECT = 20; /** Predicates longer than this have a NL after them. */ public static final int LONG_PREDICATE = 30; /** The IRI column in a prefix. */ public static final int PREFIX_IRI = 15; // Pretty writers - do object lists? // The block writers do not do object lists. public static boolean OBJECT_LISTS = true; // // Fixed column widths (unused). // public static int COLW_SUBJECT = 6 ; // public static int COLW_PREDICATE = 10 ; /** Column for start of predicate */ public static final int INDENT_PREDICATE = 8; /** Column for start of object */ public static final int INDENT_OBJECT = 8; /** Indent for triples in default graph blocks */ public static final int INDENT_GDFT = 2; /** Indent for trinples in named graph blocks */ public static final int INDENT_GNMD = 4; /** Minimum gap from S to P and from P to O */ public static final int MIN_GAP = 2; /** Minimum gap from S to P */ public static final int GAP_S_P = MIN_GAP; /** Minimum gap from P to O */ public static final int GAP_P_O = MIN_GAP; /** Whether to put in a newline after the opening { of a default graph block */ public static final boolean NL_GDFT_START = false; /** Whether to put in a newline after the opening { of a named graph block */ public static final boolean NL_GNMD_START = true; /** Whether to put the closing } of a default graph block on a newline */ public static final boolean NL_GDFT_END = true; /** Whether to put the closing } of a named graph block on a newline */ public static final boolean NL_GNMD_END = true; // Constants. public static final String rdfNS = RDF.getURI(); public static final Node RDF_type = RDF.Nodes.type; public static final Node RDF_First = RDF.Nodes.first; public static final Node RDF_Rest = RDF.Nodes.rest; public static final Node RDF_Nil = RDF.Nodes.nil; }
public class GraphContainerUtils { private static final Node RDFtype = RDF.type.asNode(); private static final Node BAG = RDF.Bag.asNode(); private static final Node ALT = RDF.Alt.asNode(); private static final Node SEQ = RDF.Seq.asNode(); private static final String membershipPattern = RDF.getURI() + "_(\\d+)"; private static final int NOT_FOUND = -9999; public static Collection<Node> containerMembers(Graph graph, Node container) { return containerMembers(graph, container, null); } public static Collection<Node> containerMembers(Graph graph, Node container, Node containerType) { if (!isContainer(graph, container, containerType)) return null; ExtendedIterator<Triple> iter = graph.find(container, Node.ANY, Node.ANY); SortedMap<Integer, Node> triples = new TreeMap<Integer, Node>(order); try { for (; iter.hasNext(); ) { Triple t = iter.next(); int index = getIndex(t); if (index == NOT_FOUND) continue; // Insert triples.put(new Integer(index), t.getObject()); } } finally { iter.close(); } return triples.values(); } // List x = new ArrayList() ; // try { // for ( ; iter.hasNext() ; ) // { // // Sort triples in a sorted set. // // Then extract. // Triple t = (Triple)iter.next() ; // String p = t.getPredicate().getURI() ; // // if ( p.matches(membershipPattern) ) // x.add(t.getObject()) ; // } // } finally { iter.close() ; } // return x ; // } public static boolean isContainerMember( Graph graph, Node container, Node containerType, Node member) { return countContainerMember(graph, container, containerType, member, true) != 0; } public static int countContainerMember( Graph graph, Node container, Node containerType, Node member) { return countContainerMember(graph, container, containerType, member, false); } private static int countContainerMember( Graph graph, Node container, Node containerType, Node member, boolean stopEarly) { if (graph == null) { Log.warn(GraphContainerUtils.class, "containerMember called with null graph"); return 0; } if (container == null) { Log.warn(GraphContainerUtils.class, "containerMember called with null list"); return 0; } if (member == null) { Log.warn(GraphContainerUtils.class, "containerMember called with null member"); return 0; } if (!isContainer(graph, container, containerType)) return 0; int count = 0; ExtendedIterator<Triple> iter = graph.find(container, Node.ANY, member); try { for (; iter.hasNext(); ) { Triple t = iter.next(); Node p = t.getPredicate(); String u = p.getURI(); if (u.matches(membershipPattern)) { count++; if (stopEarly) return count; } } } finally { iter.close(); } return count; } // public static boolean isContainer(Graph graph, Node container) // { return isContainer(graph, container, null) ; } public static boolean isContainer(Graph graph, Node container, Node containerType) { // if ( container.isLiteral() ) // return false ; if (containerType == null) return isContainer(graph, container, BAG) || isContainer(graph, container, ALT) || isContainer(graph, container, SEQ); return graph.contains(container, RDFtype, containerType); } static Pattern pattern = Pattern.compile(membershipPattern); private static int getIndex(Triple triple) { String u = triple.getPredicate().getURI(); // Must be _nnn. Matcher m = pattern.matcher(u); if (!m.find()) return NOT_FOUND; String index = m.group(1); return Integer.parseInt(index); } static ContainerOrder order = new ContainerOrder(); private static class ContainerOrder implements java.util.Comparator<Integer> { public int compare(Integer i1, Integer i2) { int index1 = i1.intValue(); int index2 = i2.intValue(); if (index1 < index2) return Expr.CMP_LESS; if (index1 > index2) return Expr.CMP_GREATER; return Expr.CMP_EQUAL; } } }