Java Code Examples for org.openrdf.model.Value#equals()

The following examples show how to use org.openrdf.model.Value#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OwlNormalizer.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private void hasValueFromList() {
	ValueFactory vf = getValueFactory();
	for (Statement st : ds.match(null, OWL.HASVALUE, null)) {
		Resource res = st.getSubject();
		Value obj = st.getObject();
		if (obj instanceof Resource) {
			BNode node = vf.createBNode();
			ds.add(res, OWL.ALLVALUESFROM, node);
			ds.add(node, RDF.TYPE, OWL.CLASS);
			BNode list = vf.createBNode();
			ds.add(node, OWL.ONEOF, list);
			ds.add(list, RDF.TYPE, RDF.LIST);
			ds.add(list, RDF.FIRST, obj);
			ds.add(list, RDF.REST, RDF.NIL);
			for (Value type : ds.match(obj, RDF.TYPE, null).objects()) {
				ds.add(node, RDFS.SUBCLASSOF, type);
			}
			for (Value prop : ds.match(res, OWL.ONPROPERTY, null).objects()) {
				for (Value range : ds.match(prop, RDFS.RANGE, null).objects()) {
					ds.add(node, RDFS.SUBCLASSOF, range);
				}
				for (Resource cls : ds.match(null, RDFS.SUBCLASSOF, res).subjects()) {
					for (Value sup : findSuperClasses(cls)) {
						if (!sup.equals(res) && !ds.match(sup, OWL.ONPROPERTY, prop).isEmpty()) {
							for (Value from : ds.match(sup, OWL.ALLVALUESFROM, null).objects()) {
								ds.add(node, RDFS.SUBCLASSOF, from);
							}
						}
					}
				}
			}
		}
	}
}
 
Example 2
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * ppp nrl:inverseProperty qqq 
 * -->
 * qqq nrl:inverseProperty ppp 
 * ppp a rdf:Property
 * qqq a rdf:Property
 * 
 * @return
 * @throws SailException
 */
private int applyRuleN3()
throws SailException
{
	int nofInferred = 0;
	
	Iterator<Statement> it1 = this.newThisIteration.match(null, NRL_InverseProperty, null);
	while (it1.hasNext()) {
		Statement stmt1 = it1.next();
		Resource ppp = stmt1.getSubject();
		if(ppp instanceof URI) {
			// infer: ppp is a property
			boolean addedPPP = addInferredStatement(ppp, RDF.TYPE, RDF.PROPERTY);
			if (addedPPP) {
				nofInferred++;
			}
		}
		Value qqq = stmt1.getObject();
		if(qqq instanceof Resource) {
			if(qqq instanceof URI) {
				// infer: qqq is a property
				boolean addedQQQ = addInferredStatement((URI)qqq, RDF.TYPE, RDF.PROPERTY);
				if (addedQQQ) {
					nofInferred++;
				}
			}
			if(! qqq.equals(ppp)) {
				// infer: qqq inverse ppp
				boolean added = addInferredStatement((Resource)qqq, NRL_InverseProperty, ppp);
				if (added) {
					nofInferred++;
				}
			}
		}
	}
	return nofInferred;
}
 
Example 3
Source File: ObjectArrayCursor.java    From anno4j with Apache License 2.0 4 votes vote down vote up
private boolean equals(Value v1, Value v2) {
	return v1 == v2 || v1 != null && v1.equals(v2);
}
 
Example 4
Source File: ObjectCursor.java    From anno4j with Apache License 2.0 4 votes vote down vote up
private boolean equals(Value v1, Value v2) {
	return v1 == v2 || v1 != null && v1.equals(v2);
}
 
Example 5
Source File: BigdataGraph.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert a unit of RDF data to an atomic unit of PG data.
 */
protected BigdataGraphAtom toGraphAtom(final URI s, final URI p, final Value o) {
        
    final String sid = factory.fromURI(s);
    final String pid = factory.fromURI(p);
    
    final BigdataGraphAtom atom;
    if (o instanceof URI) {
        
        /*
         * Either an edge or an element type statement.
         */
        if (p.equals(factory.getTypeURI()) && 
            (o.equals(factory.getVertexURI()) || o.equals(factory.getEdgeURI()))) {
            
            /*
             * Element type. 
             */
            if (o.equals(factory.getVertexURI())) {
                atom = new ExistenceAtom(sid, ElementType.VERTEX);
            } else {
                atom = new ExistenceAtom(sid, ElementType.EDGE);
            }
            
        } else {
            
            /*
             * Edge.
             */
            final String oid = factory.fromURI((URI) o);
            atom = new EdgeAtom(pid, sid, oid);
            
        }
        
    } else {
        
        /*
         * A property or the edge label.
         */
        if (p.equals(factory.getLabelURI())) {
            
            /*
             * Edge label.
             */
            final String label = factory.fromLiteral((Literal) o).toString();
            atom = new EdgeLabelAtom(sid, label);
            
        } else {
            
            /*
             * Property.
             */
            final Object oval = factory.fromLiteral((Literal) o);
            atom = new PropertyAtom(sid, pid, oval);
        
        }
        
    }
    
    return atom;

}
 
Example 6
Source File: GPO.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Remove the statement for the predicate and value if found, returning
 * true IFF the statement was removed.
 * 
 * @return <code>true</code> iff the statement was removed.
 */
public boolean remove(final GPO owner, final Value value) {

	if (value == null)
		throw new IllegalArgumentException();

	// if on m_values then move to m_removed
	LinkValue test = m_values;
	LinkValue prev = null;
	while (test != null) {
		if (value.equals(test.m_value)) {
			if (prev == null) {
				m_values = test.m_next;
			} else {
				prev.m_next = test.m_next;
			}
			// add to removed values
			test.m_next = m_removedValues;
			m_removedValues = test;

			m_size--;

			return true;
		}
		prev = test;
		test = test.m_next;
	}

	// if on m_added then just remove it
	test = m_addedValues;
	prev = null;
	while (test != null) {
		if (value.equals(test.m_value)) {
			if (prev == null) {
				m_addedValues = test.m_next;
			} else {
				prev.m_next = test.m_next;
			}

			m_size--;

			return true;
		}
		prev = test;
		test = test.m_next;
	}

	return false;
}
 
Example 7
Source File: WebTestUtils.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
/**
 * Copied from org.openrdf.query.QueryResultUtil
 */
private static boolean bindingSetsMatch(final BindingSet bs1, final BindingSet bs2) {

	if (bs1.size() != bs2.size()) {
		return false;
	}

	for (Binding binding1 : bs1) {
		Value value1 = binding1.getValue();
		Value value2 = bs2.getValue(binding1.getName());

		if ((value1 instanceof BNode) && (value2 instanceof BNode)) {
			// BNode mappedBNode = bNodeMapping.get(value1);
			//
			// if (mappedBNode != null) {
			// // bNode 'value1' was already mapped to some other bNode
			// if (!value2.equals(mappedBNode)) {
			// // 'value1' and 'value2' do not match
			// return false;
			// }
			// } else {
			// // 'value1' was not yet mapped, we need to check if 'value2'
			// // is a
			// // possible mapping candidate
			// if (bNodeMapping.containsValue(value2)) {
			// // 'value2' is already mapped to some other value.
			// return false;
			// }
			// }

			return value1.equals(value2);
		} else {
			// values are not (both) bNodes
			if ((value1 instanceof Literal) && (value2 instanceof Literal)) {
				// do literal value-based comparison for supported datatypes
				Literal leftLit = (Literal) value1;
				Literal rightLit = (Literal) value2;

				URI dt1 = leftLit.getDatatype();
				URI dt2 = rightLit.getDatatype();

				if ((dt1 != null) && (dt2 != null) && dt1.equals(dt2) && XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
						&& XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
					Integer compareResult = null;
					if (dt1.equals(XMLSchema.DOUBLE)) {
						compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
					} else if (dt1.equals(XMLSchema.FLOAT)) {
						compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
					} else if (dt1.equals(XMLSchema.DECIMAL)) {
						compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
					} else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
						compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
					} else if (dt1.equals(XMLSchema.BOOLEAN)) {
						Boolean leftBool = Boolean.valueOf(leftLit.booleanValue());
						Boolean rightBool = Boolean.valueOf(rightLit.booleanValue());
						compareResult = leftBool.compareTo(rightBool);
					} else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
						XMLGregorianCalendar left = leftLit.calendarValue();
						XMLGregorianCalendar right = rightLit.calendarValue();

						compareResult = left.compare(right);
					}

					if (compareResult != null) {
						if (compareResult.intValue() != 0) {
							return false;
						}
					} else if (!value1.equals(value2)) {
						return false;
					}
				} else if (!value1.equals(value2)) {
					return false;
				}
			} else if (!value1.equals(value2)) {
				return false;
			}
		}
	}

	return true;
}