private static List<RDFNode> asJavaList( Resource resource ) { return (resource.as( RDFList.class )).asJavaList(); }
/** * <p>Answer true if the given individual is one of the enumerated individuals in the class extension * of this class.</p> * @param res An individual to test * @return True if the given individual is in the class extension for this class. * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public boolean hasOneOf( Resource res ) { return getOneOf().contains( res ); }
/** * <p>Answer a set of all of the RDF statements whose subject is one of the cells * of this list.</p> * @return A list of the statements that form the encoding of this list. */ public Set<Statement> collectStatements() { Set<Statement> stmts = new HashSet<Statement>(); RDFList l = this; do { // collect all statements of this list cell for (Iterator<Statement> i = l.listProperties(); i.hasNext(); ) { stmts.add( i.next() ); } // move on to next cell l = l.getTail(); } while (!l.isEmpty()); return stmts; }
/** * <p>Answer an iterator over all of the individuals that are declared to be the class extension for * this class. Each element of the iterator will be an {@link OntResource}.</p> * @return An iterator over the individuals in the class extension * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public ExtendedIterator<? extends OntResource> listOneOf() { return getOneOf().iterator().mapWith( new AsMapper<OntResource>( OntResource.class ) ); }
/** Add the given value to a list which is the value of the given property */ protected void addListPropertyValue( Property p, String name, RDFNode value ) { checkProfile( p, name ); // get the list value if (hasProperty( p )) { RDFNode cur = getRequiredProperty( p ).getObject(); if (!cur.canAs( RDFList.class )) { throw new OntologyException( "Tried to add a value to a list-valued property " + p + " but the current value is not a list: " + cur ); } RDFList values = cur.as( RDFList.class ); // now add our value to the list if (!values.contains( value )){ RDFList newValues = values.with( value ); // if the previous values was nil, the return value will be a new list if (newValues != values) { removeAll( p ); addProperty( p, newValues ); } } } else { // create a new list to hold the only value we know so far addProperty( p, ((OntModel) getModel()).createList( new RDFNode[] {value} ) ); } }
/** * @see Iterator#hasNext */ @Override public boolean hasNext() { return !m_head.isEmpty(); }
/** * Creates a union {@link OntClass} from specified classes. First makes an {@link RDFList} and gives it to * {@link OntologyResourceHelper#createUnionClass(RDFList)} as a parameter. * * @param classes * {@link OntClass}es from which union class will be created * @return {@link OntClass} instance. */ public OntClass createUnionClass(List<Resource> classes) { RDFList list = ontModel.createList(); for (Resource klass : classes) { list.cons(klass); } return createUnionClass(list); }
/** * <p> * Answer the node that is the i'th element of the list, assuming that the * head is item zero. If the list is too short to have an i'th element, * throws a {@link ListIndexException}. * </p> * * @param i The index into the list, from 0 * @return The list value at index i, or null * @exception ListIndexException if the list has fewer than (i + 1) * elements. */ @Override public RDFNode get( int i ) { if (s_checkValid) { checkValid(); } checkNotNil( "Tried to get an element from the empty list" ); return findElement( false, i ).getHead(); }
copy.concatenate( list ); return copy;
/** * <p>Answer an iterator over all of the classes that are the operands of this * Boolean class expression. Each element of the iterator will be an {@link OntClass}.</p> * @return An iterator over the operands of the expression. * @exception OntProfileException If the operand property is not supported in the current language profile. */ @Override public ExtendedIterator<? extends OntClass> listOperands() { return getOperands().iterator().mapWith( new AsMapper<OntClass>( OntClass.class ) ); }
/** * <p>Answer an iterator over all of the literals that are declared to be the permissible values for * this class. Each element of the iterator will be an {@link Literal}.</p> * @return An iterator over the literals that are the permissible values * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public ExtendedIterator<Literal> listOneOf() { return getOneOf().iterator().mapWith( new AsMapper<Literal>( Literal.class ) ); }
private static AnyList convertList(Resource tso) { if (tso.canAs(RDFList.class)) { List<RDFNode> operand = tso.as(RDFList.class).asJavaList(); Any[] elements = new Any[operand.size()]; for (int i = 0; i < operand.size(); i += 1) elements[i] = RDFQ.any( operand.get(i) ); return RDFQ.list( elements ); } else { EldaException.BadSpecification( "Object " + tso + " of " + ELDA_API.textSearchOperand + " must be an RDF list." ); return /* never */ null; } }
/** * <p>Answer true if the given literal is one of the enumerated literals that are the permissible values * of this datarange.</p> * @param lit A literal to test * @return True if the given literal is in the permissible values for this class. * @exception OntProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public boolean hasOneOf( Literal lit ) { return getOneOf().contains( lit ); }
private <E> Collection<E> parseIntoCollection(RDFList list, Collection<E> l, ClassMeta<?> type, BeanPropertyMeta pMeta) throws Exception { int argIndex = 0; for (ExtendedIterator<RDFNode> ni = list.iterator(); ni.hasNext();) { E e = (E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), ni.next(), l, pMeta); l.add(e); } return l; }
@Override public List<Item> getLinkedOrderedList(Ident linkName) { List<Item> results = new ArrayList<Item>(); RDFNode resultNode = getSinglePropertyVal(linkName, false); if (resultNode != null) { RDFList rdfList = resultNode.as(RDFList.class); //System.out.println("Found rdfList[" + linkName + "] = " + rdfList); if (rdfList != null) { List<RDFNode> javaNodeList = rdfList.asJavaList(); // System.out.println("JavaNodeList = " + javaNodeList); for (RDFNode elementNode : javaNodeList) { Resource res = elementNode.asResource(); JenaResourceItem jri = makeItemOfMyJClazz(res); // new JenaResourceItem(res); results.add(jri); } } } return results; } public Resource getJenaResource() {
/** * <p>Answer true if this Boolean class expression has the given class as an operand.</p> * @param cls A class to test * @return True if the given class is an operand to this expression. * @exception OntProfileException If the operand property is not supported in the current language profile. */ @Override public boolean hasOperand( Resource cls ) { return getOperands().contains( cls ); }
/** Answer this view after modifying it to contain all the property chains defined by <code>spec</code>. */ public View addViewFromRDFList(Resource spec, ShortnameService sns) { cannotUpdateALL(); if (spec.canAs(RDFList.class)) { List<ViewProperty> properties = new ArrayList<>(); Iterator<RDFNode> list = spec.as(RDFList.class).iterator(); while(list.hasNext()) { properties.add(new ViewProperty.Base(list.next().as(Property.class))); } chains.add( new PropertyChain( properties ) ); } else { String uri = spec.asResource().getURI(); Property prop = ResourceFactory.createProperty(uri); ViewProperty vp = new ViewProperty.Base(prop); chains.add(new PropertyChain(vp)); } if (chains.size() > 0) type = Type.T_CHAINS; return this; }
private void enableDefaultMetadata(Resource root) { List<Statement> ss = root.listProperties(ELDA_API.enable_default_metadata).toList(); for (Statement s: ss) { List< RDFNode> l = s.getObject().as(RDFList.class).asJavaList(); for (RDFNode n: l) { Property p = n.as(Property.class); enabled.add(p); } } }