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

The following examples show how to use com.hp.hpl.jena.graph.Node. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: SolRDF   Source File: IntegrationTestSupertypeLayer.java    License: 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 2
Source Project: GeoTriples   Source File: GeneralNodeRelationUtil.java    License: 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 3
Source Project: SolRDF   Source File: NTriples.java    License: 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 4
Source Project: GeoTriples   Source File: BindingMaker.java    License: 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 5
/**
 * 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 6
/**
 * 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 7
/**
 * 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 8
/**
 * 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 9
/**
 * 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 10
Source Project: GeoTriples   Source File: D2RQQueryHandler.java    License: 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 11
/**
 * 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 12
/**
 * 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 13
Source Project: SolRDF   Source File: LocalDatasetGraph.java    License: 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 14
/**
 * 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 15
Source Project: semweb4j   Source File: DataTypeTesting.java    License: 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 16
Source Project: neo4jena   Source File: NeoGraph.java    License: 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 17
Source Project: SolRDF   Source File: NTriples.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link Node} representation of a given resource.
 * 
 * @param nt the resource (as string in NT format).
 * @return a {@link Node} representation of a given resource.
 */
public static Node asNode(final String nt) {
	if (isURI(nt)) {
		return internalAsURI(nt);
	} else if (isBlankNode(nt)) {
		return internalAsBlankNode(nt);
	} 
	return asLiteral(nt);
}
 
Example 18
Source Project: GeoTriples   Source File: GeneralResourceCollection.java    License: Apache License 2.0 5 votes vote down vote up
private Collection<GeneralTripleRelation> filterTripleRelations(Collection<GeneralTripleRelation> entityDescription) {
	List<GeneralTripleRelation> result = new ArrayList<GeneralTripleRelation>();
	for (GeneralTripleRelation triples: entityDescription) {
		triples = triples.orderBy(TripleRelation.SUBJECT, true);
		if (triples.selectTriple(new Triple(Node.ANY, RDF.Nodes.type, Node.ANY)) != null) {
			result.add(triples);
		}
		// TODO: The list of label properties is redundantly specified in PageServlet
		if (triples.selectTriple(new Triple(Node.ANY, RDFS.label.asNode(), Node.ANY)) != null) {
			result.add(triples);
		} else if (triples.selectTriple(new Triple(Node.ANY, SKOS.prefLabel.asNode(), Node.ANY)) != null) {
			result.add(triples);
		} else if (triples.selectTriple(new Triple(Node.ANY, DC.title.asNode(), Node.ANY)) != null) {
			result.add(triples);					
		} else if (triples.selectTriple(new Triple(Node.ANY, DCTerms.title.asNode(), Node.ANY)) != null) {
			result.add(triples);					
		} else if (triples.selectTriple(new Triple(Node.ANY, FOAF.name.asNode(), Node.ANY)) != null) {
			result.add(triples);					
		}
	}
	if (result.isEmpty()) {
		result.add(new GeneralTripleRelation(connection, entityTable, 
				entityMaker, 
				new FixedNodeMaker(RDF.type.asNode()), 
				new FixedNodeMaker(RDFS.Resource.asNode())));
	}
	return result;
}
 
Example 19
Source Project: SolRDF   Source File: LocalGraph.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public long getStatistic(final Node s, final Node p, final Node o) {
	final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult();
    try {
	    return searcher.search(
	    		result, 
	    		queryCommand(Triple.create(s, p, o), sortSpec())).getDocListAndSet().docList.matches();
	} catch (final Exception exception) {
		LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception);
		throw new SolrException(ErrorCode.SERVER_ERROR, exception);
	}	    
}
 
Example 20
/**
 * Method to create {@link ValueDomainRelationshipResource} on
 * {@link Abbreviation}
 * 
 * @param ValueDomainRelationshipTypeDescription
 * @return {@link ValueDomainRelationshipResource} on {@link Abbreviation}
 *         with a specific URI generated from
 *         {@link Abbreviation#ValueDomainRelationship
 */
public ValueDomainRelationshipResource createValueDomainRelationship(
		String valueDomainRelationshipTypeDescription) {
	if (Util.isNull(valueDomainRelationshipTypeDescription)) {
		throw new IllegalArgumentException(
				"Type Description must be specified for ValueDomainRelationship.");
	}
	Node node = Node.createURI(makeID(
			Abbreviation.ValueDomainRelationship.toString(),
			valueDomainRelationshipTypeDescription));
	ValueDomainRelationshipResource valueDomainRelationship = new ValueDomainRelationshipImpl(
			node, (EnhGraph) ontModel,
			valueDomainRelationshipTypeDescription, mdrDatabase);
	return valueDomainRelationship;
}
 
Example 21
/**
 * Method to create {@link ValueResource} on {@link Abbreviation}
 * 
 * @param valueItem
 *            Actual value associated with Enumeration Permissible Value
 * @return {@link ValueResource} on {@link Abbreviation} with a specific URI
 *         generated {@link Abbreviation#Value} and <code>valueItem</code>
 */
public ValueResource createValue(String valueItem) {
	if (Util.isNull(valueItem)) {
		throw new IllegalArgumentException(
				"Value Item must be specified for Value.");
	}
	Node node = Node.createURI(makeID(Abbreviation.Value.toString(),
			valueItem));
	ValueResource value = new ValueImpl(node, (EnhGraph) ontModel,
			valueItem, mdrDatabase);
	return value;
}
 
Example 22
Source Project: GeoTriples   Source File: JenaGraphExample.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	// Load mapping file
	Model mapModel = FileManager.get().loadModel("doc/example/mapping-iswc.ttl");
	
	// Read mapping file
	D2RQReader reader = new D2RQReader(mapModel, "http://localhost:2020/");
	Mapping mapping = reader.getMapping();
	
	// Compile mapping for D2RQ engine
	CompiledMapping compiled = mapping.compile();

	// Set up the GraphD2RQ
	GraphD2RQ g = new GraphD2RQ(compiled);

	// Create a find(spo) pattern 
	Node subject = Node.ANY;
	Node predicate = DC.date.asNode();
	Node object = Node.createLiteral("2003", null, XSDDatatype.XSDgYear);
	Triple pattern = new Triple(subject, predicate, object);

	// Query the graph
	Iterator<Triple> it = g.find(pattern);
	
	// Output query results
	while (it.hasNext()) {
		Triple t = it.next();
	    System.out.println("Published in 2003: " + t.getSubject());
	}
	g.close();
}
 
Example 23
Source Project: GeoTriples   Source File: TypedNodeMaker.java    License: Apache License 2.0 5 votes vote down vote up
public Node makeNode(ResultRow tuple) {
	String value = this.valueMaker.makeValue(tuple);
	if (value == null) {
		return null;
	}
	return this.nodeType.makeNode(value);
}
 
Example 24
/**
 * Method to create {@link ConceptualDomainRelationshipResource} on
 * {@link Abbreviation}
 * 
 * @param ConceptualDomainRelationshipTypeDescription
 * @return {@link ConceptualDomainRelationshipResource} on
 *         {@link Abbreviation} with a specific URI generated from
 *         {@link Abbreviation#ConceptualDomainRelationship
 */
public ConceptualDomainRelationshipResource createConceptualDomainRelationship(
		String conceptualDomainRelationshipTypeDescription) {
	if (Util.isNull(conceptualDomainRelationshipTypeDescription)) {
		throw new IllegalArgumentException(
				"Type Description must be specified for ConceptualDomainRelationship.");
	}
	Node node = Node.createURI(makeID(
			Abbreviation.ConceptualDomainRelationship.toString(),
			conceptualDomainRelationshipTypeDescription));
	ConceptualDomainRelationshipResource conceptualDomainRelationship = new ConceptualDomainRelationshipImpl(
			node, (EnhGraph) ontModel,
			conceptualDomainRelationshipTypeDescription, mdrDatabase);
	return conceptualDomainRelationship;
}
 
Example 25
public RepresentationClassResource createRepresentationClass(
		AdministrationRecordResource representationClassAdministrationRecord,
		StewardshipRelationshipResource administeredBy,
		SubmissionRelationshipResource submittedBy,
		RegistrationAuthorityResource registeredBy,
		AdministeredItemContextResource having) {
	if (representationClassAdministrationRecord == null) {
		throw new IllegalArgumentException(
				"AdministrationRecord must be specified for Representation Class.");
	}
	if (administeredBy == null) {
		throw new IllegalArgumentException(
				"Stewardship must be specified for RepresentationClass.");
	}
	if (submittedBy == null) {
		throw new IllegalArgumentException(
				"Submission must be specified for RepresentationClass.");
	}
	if (registeredBy == null) {
		throw new IllegalArgumentException(
				"Registration Authority must be specified for RepresentationClass.");
	}
	if (having == null) {
		throw new IllegalArgumentException(
				"Administered Item Context must be specified for RepresentationClass.");
	}
	String uniqueID = representationClassAdministrationRecord
			.getAdministeredItemIdentifier().getDataIdentifier();
	Node node = Node.createURI(makeID(
			Abbreviation.RepresentationClass.toString(), uniqueID));
	return new RepresentationClassImpl(node, (EnhGraph) ontModel,
			representationClassAdministrationRecord, administeredBy,
			submittedBy, registeredBy, having, mdrDatabase);
}
 
Example 26
/**
 * The method to create {@link ItemIdentifierResource} on
 * {@link Abbreviation}.
 * 
 * @param registrationAuthorityIdentifier
 *            The identifier for the owning Registration Authority.
 * @param uniqueID
 *            OPtional. IF not provided, then overriding method with random
 *            ID generator is called
 * @return {@link ItemIdentifierResource} on {@link Abbreviation} with a
 *         specific URI generated from {@link Abbreviation#ItemIdentifier}.
 */
public ItemIdentifierResource createItemIdentifier(
		RegistrationAuthorityIdentifierResource registrationAuthorityIdentifier,
		String uniqueID) {
	if (registrationAuthorityIdentifier == null) {
		throw new IllegalArgumentException(
				"Registration Authority Identifier must be specified for ItemIdentifier.");
	}
	Node node = Node.createURI(makeID(
			Abbreviation.ItemIdentifier.toString(), uniqueID));
	ItemIdentifierResource itemIdentifier = new ItemIdentifierImpl(node,
			(EnhGraph) ontModel, registrationAuthorityIdentifier, uniqueID,
			DEFAULT_VERSION, mdrDatabase);
	return itemIdentifier;
}
 
Example 27
/**
 * 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 28
Source Project: SolRDF   Source File: CloudDatasetGraph.java    License: 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 29
Source Project: SolRDF   Source File: NTriples.java    License: 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 30
/**
 * 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;
}