com.hp.hpl.jena.graph.Node Java Examples

The following examples show how to use com.hp.hpl.jena.graph.Node. 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: GeneralNodeRelationUtil.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
/**
 * Joins this NodeRelation with a Binding. Any row in this
 * NodeRelation that is incompatible with the binding will be
 * dropped, and any compatible row will be extended with
 * FixedNodeMakers whose node is taken from the binding.
 * 
 * FIXME: This doesn't behave correctly when a node maker is available for a given variable but produces unbound results. Everything is compatible with unbound.
 * FIXME: This ignores the condition of the binding maker, if any is present.
 * 
 * @param binding A binding to join with this NodeRelation
 * @return The joined NodeRelation
 */
public static GeneralNodeRelation extendWith(GeneralNodeRelation table, Binding binding) {
	if (binding.isEmpty()) return table;
	Map<Var,NodeMaker> extraVars = new HashMap<Var,NodeMaker>();
	GeneralNodeRelation result = table;
	for (Iterator<Var> it = binding.vars(); it.hasNext();) {
		Var var = it.next();
		Node value = binding.get(var);
		if (table.getBindingMaker().has(var)) {
			result = GeneralNodeRelationUtil.select(result, var, value);
		} else {
			extraVars.put(var, new FixedNodeMaker(value));
		}
	}
	if (!extraVars.isEmpty()) {
		extraVars.putAll(result.getBindingMaker().getNodeMakers());
		result = new GeneralNodeRelation(result.getConnection(), result.getBaseTabular(), 
				new BindingMaker(extraVars, result.getBindingMaker().getCondition()));
	}
	return result;
}
 
Example #2
Source File: DataTypeTesting.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testNewToJenaNode() throws ModelRuntimeException {
	com.hp.hpl.jena.rdf.model.Model model = ModelFactory.createDefaultModel();
	
	DatatypeLiteralImpl l1 = new DatatypeLiteralImpl("test", new URIImpl("test:funky", false));
	DatatypeLiteralImpl l2 = new DatatypeLiteralImpl("test", new URIImpl("test:funky", false));
	
	Node n1 = TypeConversion.toJenaNode(l1, model);
	Node n2 = TypeConversion.toJenaNode(l2, model);
	
	assertTrue(n1.equals(n2));
	
	Object o1 = TypeConversion.toRDF2Go(n1);
	Object o2 = TypeConversion.toRDF2Go(n2);
	
	assertTrue(o1 instanceof DatatypeLiteral);
	assertTrue(o2 instanceof DatatypeLiteral);
	
	DatatypeLiteralImpl new1 = (DatatypeLiteralImpl)o1;
	DatatypeLiteralImpl new2 = (DatatypeLiteralImpl)o2;
	
	assertTrue(new1.getValue().equals("test"));
	assertTrue(new2.getValue().equals("test"));
	assertTrue(new1.getDatatype().equals(new URIImpl("test:funky", false)));
	assertTrue(new2.getDatatype().equals(new URIImpl("test:funky", false)));
}
 
Example #3
Source File: IntegrationTestSupertypeLayer.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
/**
 * Executes a given update command both on remote and local model.
 * 
 * @param data the object holding test data (i.e. commands, queries, datafiles).
 * @throws Exception hopefully never otherwise the corresponding test fails.
 */
protected void executeUpdate(final MisteryGuest data) throws Exception {
	load(data);
	
	final String updateCommandString = readFile(data.query);
	UpdateExecutionFactory.createRemote(UpdateFactory.create(updateCommandString), SPARQL_ENDPOINT_URI).execute();

	SOLRDF_CLIENT.commit();

	UpdateAction.parseExecute(updateCommandString, memoryDataset.asDatasetGraph());
	
	final Iterator<Node> nodes = memoryDataset.asDatasetGraph().listGraphNodes();
	if (nodes != null) {
		while (nodes.hasNext()) {
			final Node graphNode = nodes.next();
			final String graphUri = graphNode.getURI();
			final Model inMemoryNamedModel = memoryDataset.getNamedModel(graphUri);
			assertIsomorphic(inMemoryNamedModel, SOLRDF_CLIENT.getNamedModel(graphUri), graphUri);		
		}
	}
	
	assertIsomorphic(memoryDataset.getDefaultModel(), SOLRDF_CLIENT.getDefaultModel(), null);			
}
 
Example #4
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Method to create {@link StewardshipRelationshipResource} on
 * {@link Abbreviation}
 * 
 * @param administerOrganization
 *            Administer Organization
 * @param administer
 *            Contact Details of Administer from Organization
 * @return {@link StewardshipRelationshipResource} on {@link Abbreviation}
 *         with a specific URI generated from
 *         {@link Abbreviation#Stewardship} and parameters
 */
public StewardshipRelationshipResource createStewardshipRelationship(
		OrganizationResource administerOrganization,
		StewardshipResource administer) {
	if (administerOrganization == null) {
		throw new IllegalArgumentException(
				"Organization must be specified for the StewardshipRelationship");
	}
	if (administer == null) {
		throw new IllegalArgumentException(
				"Submission must be specified for the StewardshipRelationship");
	}
	Node node = Node.createURI(makeID(Abbreviation.Stewardship,
			administerOrganization.getOrganizationName(), administer
					.getStewardshipContact().getContactName()));
	StewardshipRelationshipResource stewardshipRelationship = new StewardshipRelationshipImpl(
			node, (EnhGraph) ontModel, administerOrganization, administer,
			mdrDatabase);
	return stewardshipRelationship;
}
 
Example #5
Source File: NeoGraph.java    From neo4jena with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the given triple from the graph.
 */
@Override
public void delete(Triple triple) throws DeleteDeniedException {
	Transaction tx=graphdb.beginTx();
	org.neo4j.graphdb.Node subject = nodeFactory.get(triple.getSubject());
	System.out.println("Subject node:" + subject.getProperty("uri"));
	if(subject!=null) {
		org.neo4j.graphdb.Node object = nodeFactory.get(triple.getObject());
		System.out.println("Object node:" + object.getProperty("uri"));
		if(object!=null) {
			Relationship relation = relationshipFactory.get(subject, triple.getPredicate().getURI(), object);
			System.out.println("Relationship:" +relation.getProperty("uri"));
			if(!subject.hasRelationship())
				subject.delete();
			if(triple.getObject().isLiteral())
				object.delete();
			else if(!object.hasRelationship())
				object.delete();
		}
		tx.success();
	}	
}
 
Example #6
Source File: NTriples.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link String} representation of the given literal.
 * 
 * @param literal the literal node.
 * @return a {@link String} representation of the given literal.
 */
public static String asNtLiteral(final Node literal) {
	final StringBuilder buffer = new StringBuilder("\"");
	escapeAndAppend(String.valueOf(literal.getLiteral().getLexicalForm()), buffer);
	buffer.append("\"");
	final String language = literal.getLiteralLanguage();
	if (isNotNullOrEmptyString(language)) {
		buffer.append("@").append(language);
	}
	
	final String datatypeURI = literal.getLiteralDatatypeURI();
	if (datatypeURI != null) {
		buffer.append("^^");
		escapeAndAppend(datatypeURI, buffer);
	}
	return buffer.toString();
}
 
Example #7
Source File: LocalDatasetGraph.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean _containsGraph(final Node graphNode) {
    final SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand();
    cmd.setQuery(new MatchAllDocsQuery());
    cmd.setLen(0);
    cmd.setFilterList(new TermQuery(new Term(Field.C, asNtURI(graphNode))));				
    
    final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult();
    try {
		request.getSearcher().search(result, cmd);
	    return result.getDocListAndSet().docList.matches() > 0;
	} catch (final Exception exception) {
		LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception);
		throw new SolrException(ErrorCode.SERVER_ERROR, exception);
	}	    
}
 
Example #8
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The method to create {@link ClassificationSchemeItemRelationshipResource}
 * on {@link Abbreviation}.
 * 
 * @param classificationSchemeItemRelationshipTypeDescription
 * 
 * @return {@link ClassificationSchemeItemRelationshipResource} on
 *         {@link Abbreviation} with a specific URI generated from
 *         {@link Abbreviation#ClassificationSchemeItemRelationship}.
 */
public ClassificationSchemeItemRelationshipResource createClassificationSchemeItemRelationship(
		String classificationSchemeItemRelationshipTypeDescription) {
	if (Util.isNull(classificationSchemeItemRelationshipTypeDescription)) {
		throw new IllegalArgumentException(
				"Classification Scheme Item Relationship Type Description must be specified for ClassificationSchemeItemRelationship.");
	}
	Node node = Node.createURI(makeID(
			Abbreviation.ClassificationSchemeItemRelationship.toString(),
			classificationSchemeItemRelationshipTypeDescription));
	ClassificationSchemeItemRelationshipResource classificationSchemeItemRelationship = new ClassificationSchemeItemRelationshipImpl(
			node, (EnhGraph) ontModel,
			classificationSchemeItemRelationshipTypeDescription,
			mdrDatabase);
	return classificationSchemeItemRelationship;

}
 
Example #9
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Method to create {@link UnitOfMeasureResource} on {@link Abbreviation}
 * 
 * @param unitOfMeasureName
 * @param unitOfMeasurePrecision
 * @return {@link UnitOfMeasureResource} on {@link Abbreviation} with a
 *         specific URI generated from {@link Abbreviation#UnitOfMeasure}
 *         and parameters
 */
public UnitOfMeasureResource createUnitOfMeasure(String unitOfMeasureName,
		Integer unitOfMeasurePrecision) {
	if (Util.isNull(unitOfMeasureName)) {
		throw new IllegalArgumentException(
				"Name must be speicified for UnitOfMeasure");
	}
	if (unitOfMeasurePrecision == null) {
		throw new IllegalArgumentException(
				"Precision must be specified for UnitOfMeasure");
	}

	Node node = Node.createURI(makeID(
			Abbreviation.UnitOfMeasure.toString(), unitOfMeasureName,
			unitOfMeasurePrecision.toString()));
	UnitOfMeasureResource unitOfMeasure = new UnitOfMeasureImpl(node,
			(EnhGraph) ontModel, unitOfMeasureName, unitOfMeasurePrecision,
			mdrDatabase);
	return unitOfMeasure;
}
 
Example #10
Source File: BindingMaker.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
public Binding makeBinding(ResultRow row) {
	if (condition != null) {
		String value = row.get(condition);
		if (value == null || "false".equals(value) || "0".equals(value) || "".equals(value)) {
			return null;
		}
	}
	BindingMap result = new BindingHashMap();
	for (Var variableName: nodeMakers.keySet()) {
		Node node = nodeMakers.get(variableName).makeNode(row);
		if (node == null) {
			return null;
		}
		result.add(Var.alloc(variableName), node);
	}
	return result;
}
 
Example #11
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Method to create {@link AdministeredItemContextResource} on
 * {@link Abbreviation}. {@link AdministeredItemContextResource} is created
 * to handle the related n-ary relation which exist in the ISO-11179-3
 * standard.
 * 
 * @param context
 *            The {@link ContextResource} with which this created
 *            {@link AdministeredItemContextResource} will be associated.
 * @param terminologicalEntry
 *            The {@link TerminologicalEntryResource} with which this
 *            created {@link AdministeredItemContextResource} will be
 *            associated.
 * @return {@link AdministeredItemContextIIND} on {@link Abbreviation} with
 *         a specific URI genereted from
 *         {@link Abbreviation#AdministeredItemContext} and uniqueID of the
 *         associated {@link ContextResource}.
 */
public AdministeredItemContextResource createAdministeredItemContext(
		ContextResource context,
		TerminologicalEntryResource terminologicalEntry) {
	if (context == null) {
		throw new IllegalArgumentException(
				"Context must be specified for the AdministeredItemContext");
	}
	if (terminologicalEntry == null) {
		throw new IllegalArgumentException(
				"TerminologicalEntry must be specified for the AdministeredItemContext");
	}
	Node node = Node.createURI(makeID(
			Abbreviation.AdministeredItemContext.toString(),
			generateUniqueID()));
	AdministeredItemContextResource administeredItemContext = new AdministeredItemContextImpl(
			node, (EnhGraph) ontModel, context, terminologicalEntry,
			mdrDatabase);
	return administeredItemContext;
}
 
Example #12
Source File: D2RQQueryHandler.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
public BindingQueryPlan prepareBindings(GraphQuery q, Node[] variables) {   
	this.variables = variables;
	this.indexes = new HashMap<Node,Integer>();
	for (int i = 0; i < variables.length; i++) {
		indexes.put(variables[i], new Integer(i));
	}
	BasicPattern pattern = new BasicPattern();
	for (Triple t: q.getPattern()) {
		pattern.add(t);
	}
	Plan plan = QueryEngineD2RQ.getFactory().create(new OpBGP(pattern), dataset, null, null);
	final ExtendedIterator<Domain> queryIterator = new Map1Iterator<Binding,Domain>(new BindingToDomain(), plan.iterator());
	return new BindingQueryPlan() {
		public ExtendedIterator<Domain> executeBindings() {
			return queryIterator;
		}
	};
}
 
Example #13
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Method to create {@link ReferenceDocumentResource} on
 * {@link Abbreviation}
 * 
 * @param referenceDocumentIdentifier
 *            Identifier for the Reference Document.
 * @param providedBy
 *            Organization which provides the Documents
 * @param referenceDocumentTypeDescription
 *            Optional. Type Desctiptor for the Reference Document.
 * 
 * @param referenceDocumentLanguageIdentifier
 *            Optional. Language Identifier for the Reference Document.
 * 
 * @param referenceDocumentTitle
 *            Optional. Title of the Reference Document
 * @return {@link ReferenceDocumentResource} on {@link Abbreviation} with a
 *         specific URI generated from
 *         {@link Abbreviation#ReferenceDocument} and
 *         <code>referenceDocumentIdentifier</code>
 */
public ReferenceDocumentResource createReferenceDocument(
		String referenceDocumentIdentifier,
		OrganizationResource providedBy,
		String referenceDocumentTypeDescription,
		LanguageIdentificationResource referenceDocumentLanguageIdentifier,
		String referenceDocumentTitle) {
	if (Util.isNull(referenceDocumentIdentifier)) {
		throw new IllegalArgumentException(
				"Reference Document Identifier must be specified for ReferenceDocument.");
	}
	if (providedBy == null) {
		throw new IllegalArgumentException(
				"Providing Organization must be specified for the ReferenceDocuments");
	}
	Node node = Node.createURI(makeID(Abbreviation.ReferenceDocument,
			referenceDocumentIdentifier));

	ReferenceDocumentResource referenceDocument = new ReferenceDocumentImpl(
			node, (EnhGraph) ontModel, referenceDocumentIdentifier,
			providedBy, referenceDocumentTypeDescription,
			referenceDocumentLanguageIdentifier, referenceDocumentTitle,
			mdrDatabase);
	return referenceDocument;
}
 
Example #14
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The method to create {@link ContactResource} on {@link Abbreviation}.
 * 
 * @param contactInformation
 *            Information to enable a Contact to be located or communicated
 *            with.
 * @param contactName
 *            The name of the Contact.
 * @param contactTitle
 *            Optional. The name of the position held by the Contact.
 * @return {@link ContactResource} on {@link Abbreviation} with a specific
 *         URI generated from contactName.
 */
public ContactResource createContact(String contactInformation,
		String contactName, String contactTitle) {
	if (Util.isNull(contactInformation)) {
		throw new IllegalArgumentException(
				"Contact Information must be specified  for Contact.");
	}
	if (Util.isNull(contactName)) {
		throw new IllegalArgumentException(
				"Contact Name must be specified  for Contact.");
	}

	Node node = Node.createURI(makeID(Abbreviation.Contact.toString(),
			contactName));
	ContactResource contact = new ContactImpl(node, (EnhGraph) ontModel,
			contactInformation, contactName, contactTitle, mdrDatabase);
	return contact;
}
 
Example #15
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Method to create {@link DatatypeResource} on {@link Abbreviation}
 * 
 * @param datatypeName
 *            name of the Datatype
 * @param datatypeDescription
 *            Optional. Description for Datatype
 * @param datatypeSchemeReference
 *            External Scheme Reference for Datatype
 * @param datatypeAnnotation
 *            Optional.
 * @return {@link DatatypeResource} on {@link Abbreviation} with a specific
 *         URI generated from {@link Abbreviation#Datatype} and parameters
 */
public DatatypeResource createDatatype(String datatypeName,
		String datatypeDescription, String datatypeSchemeReference,
		String datatypeAnnotation) {
	if (Util.isNull(datatypeName)) {
		throw new IllegalArgumentException(
				"Name must be specified for Datatype.");
	}
	if (Util.isNull(datatypeSchemeReference)) {
		throw new IllegalArgumentException(
				"Scheme Reference must be specified for Datatype");
	}

	Node node = Node.createURI(makeID(Abbreviation.Datatype.toString(),
			datatypeName, datatypeSchemeReference));
	DatatypeResource datatype = new DatatypeImpl(node, (EnhGraph) ontModel,
			datatypeName, datatypeDescription, datatypeSchemeReference,
			datatypeAnnotation, mdrDatabase);
	return datatype;
}
 
Example #16
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Method to create {@link SubmissionRelationshipResource} on
 * {@link Abbreviation}
 * 
 * @param submissionOrganization
 *            Submitter Organization
 * @param submitter
 *            Contact Details of Submitter from Organization
 * @return {@link SubmissionRelationshipResource} on {@link Abbreviation}
 *         with a specific URI generated from
 *         {@link Abbreviation#Submission} and parameters
 */
public SubmissionRelationshipResource createSubmissionRelationship(
		OrganizationResource submissionOrganization,
		SubmissionResource submitter) {
	if (submissionOrganization == null) {
		throw new IllegalArgumentException(
				"Organization must be specified for the SubmissionRelationship");
	}
	if (submitter == null) {
		throw new IllegalArgumentException(
				"Submission must be specified for the SubmissionRelationship");
	}
	Node node = Node.createURI(makeID(Abbreviation.Submission,
			submissionOrganization.getOrganizationName(), submitter
					.getSubmissionContact().getContactName()));
	SubmissionRelationshipResource submissionRelationship = new SubmissionRelationshipImpl(
			node, (EnhGraph) ontModel, submissionOrganization, submitter,
			mdrDatabase);
	return submissionRelationship;
}
 
Example #17
Source File: LocalGraph.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
public void performAdd(final Triple triple) {
	updateCommand.clear();
	
	final SolrInputDocument document = new SolrInputDocument();
	this.updateCommand.solrDoc = document;
	document.setField(Field.C, graphNodeStringified);
	document.setField(Field.S, asNt(triple.getSubject()));
	document.setField(Field.P, asNtURI(triple.getPredicate()));
	document.setField(Field.ID, UUID.nameUUIDFromBytes(
			new StringBuilder()
				.append(graphNodeStringified)
				.append(triple.getSubject())
				.append(triple.getPredicate())
				.append(triple.getObject())
				.toString().getBytes()).toString());
	
	final String o = asNt(triple.getObject());
	document.setField(Field.O, o);

	final Node object = triple.getObject();
	if (object.isLiteral()) {
		final String language = object.getLiteralLanguage();
		document.setField(Field.LANG, isNotNullOrEmptyString(language) ? language : NULL_LANGUAGE);				

		final RDFDatatype dataType = object.getLiteralDatatype();
		final Object value = object.getLiteralValue();
		registry.get(dataType != null ? dataType.getURI() : null).inject(document, value);
	} else {
		registry.catchAllFieldInjector.inject(document, o);
	}			

	try {
		updateProcessor.processAdd(updateCommand);
	} catch (final Exception exception) {
		LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception);
		throw new AddDeniedException(exception.getMessage(), triple);
	}
}
 
Example #18
Source File: NTriples.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link Node} representation of a blank node.
 * 
 * @param blankNodeAsString the resource (as string in NT format).
 * @return a {@link Node} representation of a blank node
 */		
public static Node asBlankNode(final String blankNodeAsString) {
	if (isBlankNode(blankNodeAsString)) {
		return internalAsBlankNode(blankNodeAsString);
	}
	throw new IllegalArgumentException(blankNodeAsString);
}
 
Example #19
Source File: StatementJena29Impl.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Construct a statement.
 * 
 * @param model
 * @param s may not be {@code null}
 * @param p may not be {@code null}
 * @param o may not be {@code null}
 */
public StatementJena29Impl(org.ontoware.rdf2go.model.Model model, Node s, Node p, Node o) {
	assert s != null;
	assert p != null;
	assert o != null;
	this.model = model;
	this.s = s;
	this.p = p;
	this.o = o;
}
 
Example #20
Source File: StatementJena29Impl.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Contruct a quadruple or supply {@code null} as context.
 * 
 * @param c
 * @param s may not be {@code null}
 * @param p may not be {@code null}
 * @param o may not be {@code null}
 */
public StatementJena29Impl(Node c, Node s, Node p, Node o) {
	assert s != null;
	assert p != null;
	assert o != null;
	this.c = c;
	this.s = s;
	this.p = p;
	this.o = o;
}
 
Example #21
Source File: ProcessEventObjectsStream.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static public String matchSingleTmx(Node tmx, DatasetGraph g, Model m){
    String sq="";
    if (g.contains(null, tmx, typeNode, instantNode)) { // One Instant
        sq += "?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Instant> . ";
        for (Iterator<Quad> iter = g.find(null, tmx, specificTimeNode, null); iter.hasNext(); ) {
            Quad q = iter.next();
            sq += "?t <http://www.w3.org/TR/owl-time#inDateTime> <" + q.asTriple().getObject() + "> . ";
        }
    } else { // One Interval

        String intervalQuery = "SELECT ?begin ?end WHERE { <" + tmx + ">  <http://www.w3.org/TR/owl-time#hasBeginning> ?begin ; <http://www.w3.org/TR/owl-time#hasEnd> ?end . }";

        Query inQuery = QueryFactory.create(intervalQuery);

        // Create a single execution of this query, apply to a model
        // which is wrapped up as a Dataset
        QueryExecution inQexec = QueryExecutionFactory.create(inQuery, m);

        try {
            // Assumption: it’s a SELECT query.
            ResultSet inrs = inQexec.execSelect();
            // The order of results is undefined.
            for (; inrs.hasNext(); ) {
                QuerySolution evrb = inrs.nextSolution();
                // Get title - variable names do not include the ’?’
                String begin = evrb.get("begin").toString();
                String end = evrb.get("end").toString();

                String unionQuery = "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Interval> . ?t <http://www.w3.org/TR/owl-time#hasBeginning> <" + begin + "> ; <http://www.w3.org/TR/owl-time#hasEnd> <" + end + "> . } ";
                unionQuery += "UNION ";
                unionQuery += "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestBeginTimeStamp> ?t1 . ?t1 a <http://www.w3.org/TR/owl-time#Instant> . ?t1 <http://www.w3.org/TR/owl-time#inDateTime> <" + begin + "> . ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestEndTimeStamp> ?t2 . ?t2 a <http://www.w3.org/TR/owl-time#Instant> . ?t2 <http://www.w3.org/TR/owl-time#inDateTime> <" + end + "> . } ";
                sq += unionQuery;
            }
        } finally {
            inQexec.close();
        }
    }
    return sq;
}
 
Example #22
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The method to create {@link PropertyResource} on {@link Abbreviation}.
 * 
 * @param propertyAdministrationRecord
 *            The Administration Record for a Property.
 * @param administeredBy
 *            An Administered Item is administered by an
 *            {@link OrganizationResource} represented by the
 *            {@link StewardshipRelationshipImpl}.
 * @param submittedBy
 *            An Administered Item is submitted by an
 *            {@link OrganizationResource} represented by the
 *            {@link SubmissionRelationshipImpl}.
 * @param registeredBy
 *            An {@link AdministeredItemImpl} is registered by a
 *            {@link RegistrationAuthorityImpl} represented by the
 *            relationship registration.
 * 
 * @param having
 *            An {@link AdministeredItemResource} has to have at least one
 *            {@link AdministeredItemContextImpl}.
 * @return {@link PropertyResource} on {@link Abbreviation} with a specific
 *         URI generated from {@link Abbreviation#Property}.
 */
public PropertyResource createProperty(
		AdministrationRecordResource propertyAdministrationRecord,
		StewardshipRelationshipResource administeredBy,
		SubmissionRelationshipResource submittedBy,
		RegistrationAuthorityResource registeredBy,
		AdministeredItemContextResource having) {
	if (propertyAdministrationRecord == null) {
		throw new IllegalArgumentException(
				"Administration Record must be specified for Property.");
	}
	if (administeredBy == null) {
		throw new IllegalArgumentException(
				"StewardshipRelationship must be specified for Classification Scheme");
	}
	if (submittedBy == null) {
		throw new IllegalArgumentException(
				"SubmissionRelationship must be specified for ClassificationScheme");
	}
	if (registeredBy == null) {
		throw new IllegalArgumentException(
				"Registration Authority must be specified for Classification Scheme");
	}
	if (having == null) {
		throw new IllegalArgumentException(
				"Administered Item Context must be specified for Classification Scheme");
	}
	String uniqueID = propertyAdministrationRecord
			.getAdministeredItemIdentifier().getDataIdentifier();
	Node node = Node.createURI(makeID(Abbreviation.Property.toString(),
			uniqueID));
	PropertyResource property = new PropertyImpl(node, (EnhGraph) ontModel,
			propertyAdministrationRecord, administeredBy, submittedBy,
			registeredBy, having, mdrDatabase);
	return property;
}
 
Example #23
Source File: PrettyPrinter.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public static String toString(Model m, PrefixMapping prefixes) {
	StringBuilder result = new StringBuilder();
	Iterator<Triple> it = m.getGraph().find(Node.ANY, Node.ANY, Node.ANY);
	while (it.hasNext()) {
		result.append(toString(it.next(), prefixes));
		result.append(NEWLINE);
	}
	return result.toString();
}
 
Example #24
Source File: CompiledD2RQMapping.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public List<String> getResourceCollectionNames(Node forNode) {
	List<String> result = new ArrayList<String>();
	for (String name: resourceCollections.keySet()) {
		if (resourceCollections.get(name).mayContain(forNode)) {
			result.add(name);
		}
	}
	Collections.sort(result);
	return result;
}
 
Example #25
Source File: NeoGraph.java    From neo4jena with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the grpah is empty or not
 */
@Override
public boolean isEmpty() {
	Transaction tx = graphdb.beginTx();
	Iterable<org.neo4j.graphdb.Node> nodes= GlobalGraphOperations.at(graphdb).getAllNodes();
	boolean empty = nodes.iterator().hasNext();
	tx.success();
	return !empty;
}
 
Example #26
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The method to create {@link RegistrationAuthorityResource} on
 * {@link Abbreviation}
 * 
 * @param registrationAuthorityIdentifier
 *            Identifier of Registration Authority
 * @param documentationLanguageIdentifier
 *            Language Identification for Documentation
 * @param organizationName
 *            Name of the Organization
 * @param organizationMailAddress
 *            Optional. Mail Address of the Organization
 * @param representedBy
 *            Person who perform the administrative steps to register
 *            Administered Items
 * 
 * @return {@link RegistrationAuthorityResource} on {@link Abbreviation}
 *         with a specific URI generated from
 *         {@link Abbreviation#RegistrationAuthority} and parameter
 *         <code>registrationAuthorityIdentifier</code>
 */
public RegistrationAuthorityResource createRegistrationAuthority(
		RegistrationAuthorityIdentifierResource registrationAuthorityIdentifier,
		LanguageIdentificationResource documentationLanguageIdentifier,
		String organizationName, String organizationMailAddress,
		RegistrarResource representedBy) {
	if (registrationAuthorityIdentifier == null) {
		throw new IllegalArgumentException(
				"Registration Authority Identifier must be specified for RegistrationAuthority");
	}
	if (documentationLanguageIdentifier == null) {
		throw new IllegalArgumentException(
				"Documentation Language Identifier must be specified for RegistrationAuthority");
	}
	if (Util.isNull(organizationName)) {
		throw new IllegalArgumentException(
				"Organization Name must be specified for the RegistrationAuthority");
	}
	if (representedBy == null) {
		throw new IllegalArgumentException(
				"Registrar must be specified for RegistrationAuthoity");
	}

	Node node = Node
			.createURI(makeID(Abbreviation.RegistrationAuthority,
					registrationAuthorityIdentifier
							.getOrganizationIdentifier(),
					registrationAuthorityIdentifier
							.getOrganizationPartIdentifier()));
	RegistrationAuthorityResource registrationAuthority = new RegistrationAuthorityImpl(
			node, (EnhGraph) ontModel, registrationAuthorityIdentifier,
			documentationLanguageIdentifier, organizationName,
			organizationMailAddress, representedBy, mdrDatabase);
	return registrationAuthority;
}
 
Example #27
Source File: CloudDatasetGraph.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean _containsGraph(final Node graphNode) {
	final SolrQuery query = new SolrQuery("*:*")
		.addFilterQuery(fq(Field.C, asNtURI(graphNode)))
		.setRows(0);
	try {
		return cloud.query(query).getResults().getNumFound() > 0;
	} catch (final Exception exception) {
		LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception);
		throw new SolrException(ErrorCode.SERVER_ERROR, exception);
	}			    
}
 
Example #28
Source File: ProcessEventObjectsStream.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
private static void inferIdentityRelations(String sparqlQuery, boolean matchILI, boolean matchLemma, boolean matchMultiple, int iliSize, Node eventId, DatasetGraph g) {
    if (matchILI || matchLemma) {
        sparqlQuery += "GROUP BY ?ev";
    }
    HttpAuthenticator authenticator = new SimpleAuthenticator(user, pass.toCharArray());
    QueryExecution x = QueryExecutionFactory.sparqlService(serviceEndpoint, sparqlQuery, authenticator);
    ResultSet resultset = x.execSelect();
    int threshold;
    while (resultset.hasNext()) {
        QuerySolution solution = resultset.nextSolution();
        if (matchILI || matchLemma) {
            if (matchILI)
                threshold = conceptMatchThreshold;
            else
                threshold=phraseMatchThreshold;

            if (matchMultiple) {
                //System.out.println(solution);
                if (checkIliLemmaThreshold(iliSize, solution.get("conceptcount").asLiteral().getInt(), solution.get("myconceptcount").asLiteral().getInt(), threshold)) {
                    insertIdentity(g, eventId, solution.get("ev").asNode());
                }
            } else {
                if (checkIliLemmaThreshold(1, solution.get("conceptcount").asLiteral().getInt(), 1, threshold)) {
                    insertIdentity(g, eventId, solution.get("ev").asNode());
                }
            }
        } else {
            insertIdentity(g, eventId, solution.get("ev").asNode());
        }
    }
}
 
Example #29
Source File: MDRResourceFactory.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method to create {@link LanguageSectionResource} on {@link Abbreviation}
 * 
 * @param languageSectionLanguageIdentifier
 *            {@link LanguageIdentificationResource} identifying the
 *            LanguageSection.
 * @return {@link LanguageSectionResource} on {@link Abbreviation} with a
 *         specific URI genereted from {@link Abbreviation#LanguageSection}
 *         and parameter
 */
public LanguageSectionResource createLanguageSection(
		LanguageIdentificationResource languageSectionLanguageIdentifier) {
	if (languageSectionLanguageIdentifier == null) {
		throw new IllegalArgumentException(
				"Language Identification must be specified for Language Section");
	}
	String uniqueID = generateUniqueID();
	Node node = Node.createURI(makeID(Abbreviation.LanguageSection,
			uniqueID));
	LanguageSectionResource languageSection = new LanguageSectionImpl(node,
			(EnhGraph) ontModel, languageSectionLanguageIdentifier,
			mdrDatabase);
	return languageSection;
}
 
Example #30
Source File: R2RMLCompiler.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public List<String> getResourceCollectionNames(Node forNode) {
	checkCompiled();
	List<String> result = new ArrayList<String>();
	for (String name: resourceCollections.keySet()) {
		if (resourceCollections.get(name).mayContain(forNode)) {
			result.add(name);
		}
	}
	Collections.sort(result);
	return result;
}