Java Code Examples for com.hp.hpl.jena.rdf.model.Model#setNsPrefix()

The following examples show how to use com.hp.hpl.jena.rdf.model.Model#setNsPrefix() . 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: John_BaseXMLWriter.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
private void generateDoctypeDeclaration(Model model, PrintWriter pw) {
	String rdfns = RDF.getURI();
	String rdfRDF = model.qnameFor(rdfns + "RDF");
	if (rdfRDF == null) {
		model.setNsPrefix("rdf", rdfns);
		rdfRDF = "rdf:RDF";
	}
	Map<String, String> prefixes = model.getNsPrefixMap();
	pw.print("<!DOCTYPE " + rdfRDF + " [");
	for (Iterator<String> it = prefixes.keySet().iterator(); it.hasNext();) {
		String prefix = it.next();
		if (isPredefinedEntityName(prefix))
			continue;
		pw.print(newline
				+ "  <!ENTITY "
				+ strForPrefix(prefix)
				+ " '"
				+ Util.substituteEntitiesInEntityValue(prefixes.get(prefix))
				+ "'>");
	}
	pw.print("]>" + newline);
}
 
Example 2
Source File: ResourcesUri.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static public void prefixSimpleModel (Model model) {
    model.setNsPrefix("wn", ResourcesUri.wn);
    model.setNsPrefix("ili", ResourcesUri.ili);
    model.setNsPrefix("fn", ResourcesUri.fn);
    model.setNsPrefix("nwrdata", ResourcesUri.nwrdata);
    model.setNsPrefix("nwrentities", ResourcesUri.nwrentities);
    model.setNsPrefix("nwrnon-entities", ResourcesUri.nwrnonentities);
    model.setNsPrefix("nwrontology", ResourcesUri.nwrontology);
    model.setNsPrefix("oldbailey", ResourcesUri.oldbaily);
    model.setNsPrefix("ceo", ResourcesUri.ceo);
    model.setNsPrefix("eso", ResourcesUri.eso);
    model.setNsPrefix("dbpr", ResourcesUri.dbpr);
    model.setNsPrefix("dbpo", ResourcesUri.dbpo);
    model.setNsPrefix("pb", ResourcesUri.pb);
    model.setNsPrefix("gaf", ResourcesUri.gaf);
    model.setNsPrefix("sem", ResourcesUri.sem);
    model.setNsPrefix("owl", ResourcesUri.owl);
    model.setNsPrefix("time", ResourcesUri.owltime);
    model.setNsPrefix("skos", ResourcesUri.skos);
    model.setNsPrefix("rdf", ResourcesUri.rdf);
    model.setNsPrefix("rdfs", ResourcesUri.rdfs);
}
 
Example 3
Source File: GetPerspectiveRelations.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
public static void perspectiveRelationsToTrig (String pathToTrigFile,
                                               KafSaxParser kafSaxParser,
                                               String project,
                                               ArrayList<PerspectiveObject> sourcePerspectiveObjects,
                                               ArrayList<PerspectiveObject> authorPerspectiveObjects) {
        try {
            OutputStream fos = new FileOutputStream(pathToTrigFile);
            Dataset ds = TDBFactory.createDataset();
            Model defaultModel = ds.getDefaultModel();
            ResourcesUri.prefixModelGaf(defaultModel);
            ResourcesUri.prefixModelNwr(defaultModel);
            defaultModel.setNsPrefix("rdf", ResourcesUri.rdf);
            defaultModel.setNsPrefix("rdfs", ResourcesUri.rdfs);
            String docId = kafSaxParser.getKafMetaData().getUrl().replaceAll("#", "HASH");
            if (!docId.toLowerCase().startsWith("http")) {
                docId = ResourcesUri.nwrdata + project + "/" + docId;
            }
            JenaSerialization.addDocMetaData(docId, kafSaxParser, project);
            String attrBase = kafSaxParser.getKafMetaData().getUrl()+"_"+"s";
            JenaSerialization.addJenaPerspectiveObjects(attrBase, ResourcesUri.grasp, "wasAttributedTo", sourcePerspectiveObjects, 1);
            attrBase = kafSaxParser.getKafMetaData().getUrl()+"_"+"d";
            JenaSerialization.addJenaPerspectiveObjects(attrBase, ResourcesUri.prov, "wasDerivedFrom", authorPerspectiveObjects, sourcePerspectiveObjects.size()+1);
            RDFDataMgr.write(fos, ds, RDFFormat.TRIG_PRETTY);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
}
 
Example 4
Source File: ResourcesUri.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static public void prefixModel (Model model) {
        model.setNsPrefix("wn", ResourcesUri.wn);
        model.setNsPrefix("ili", ResourcesUri.ili);
      //  model.setNsPrefix("cornetto", ResourcesUri.cornetto);
        model.setNsPrefix("fn", ResourcesUri.fn);
        model.setNsPrefix("nwrdata", ResourcesUri.nwrdata);
        model.setNsPrefix("nwrentities", ResourcesUri.nwrentities);
        model.setNsPrefix("nwrnon-entities", ResourcesUri.nwrnonentities);
        model.setNsPrefix("nwrontology", ResourcesUri.nwrontology);
        model.setNsPrefix("ceo", ResourcesUri.ceo);
        model.setNsPrefix("eso", ResourcesUri.eso);
        model.setNsPrefix("dbpr", ResourcesUri.dbpr);
        model.setNsPrefix("dbpo", ResourcesUri.dbpo);
        model.setNsPrefix("pb", ResourcesUri.pb);

/*      //REMOVED DUE TO ILLEGAL CHARACTERS
        model.setNsPrefix("vn", ResourcesUri.vn);
        model.setNsPrefix("pb", ResourcesUri.pb);
        model.setNsPrefix("nb", ResourcesUri.nb);
*/
        model.setNsPrefix("gaf", ResourcesUri.gaf);
        model.setNsPrefix("sem", ResourcesUri.sem);
        model.setNsPrefix("owl", ResourcesUri.owl);
        model.setNsPrefix("time", ResourcesUri.owltime);
        model.setNsPrefix("skos", ResourcesUri.skos);
       /* REMOVED DUE TO PROBLEMS WITH SESAME
        model.setNsPrefix("eurovoc", ResourcesUri.eurovoc);
        */
        model.setNsPrefix("rdf", ResourcesUri.rdf);
        model.setNsPrefix("rdfs", ResourcesUri.rdfs);
    }
 
Example 5
Source File: ResourcesUri.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static public void prefixModelNwr (Model model) {
    model.setNsPrefix("nwr", ResourcesUri.nwr);
    model.setNsPrefix("nwrauthor", ResourcesUri.nwrauthor);
    model.setNsPrefix("nwrpublisher", ResourcesUri.nwrpublisher);
    model.setNsPrefix("nwrmagazine", ResourcesUri.nwrmagazine);
   // model.setNsPrefix("nwrsourceowner", ResourcesUri.nwrsourceowner);
}
 
Example 6
Source File: ResourceDescriptionServlet.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws IOException, ServletException {
	D2RServer server = D2RServer.fromServletContext(getServletContext());
	server.checkMappingFileChanged();
	String relativeResourceURI = request.getRequestURI().substring(
			request.getContextPath().length()
					+ request.getServletPath().length());
	// Some servlet containers keep the leading slash, some don't
	if (!"".equals(relativeResourceURI)
			&& "/".equals(relativeResourceURI.substring(0, 1))) {
		relativeResourceURI = relativeResourceURI.substring(1);
	}
	if (request.getQueryString() != null) {
		relativeResourceURI = relativeResourceURI + "?"
				+ request.getQueryString();
	}

	/* Determine service stem, i.e. vocab/ in /[vocab/]data */
	int servicePos;
	if (-1 == (servicePos = request.getServletPath().indexOf(
			"/" + D2RServer.getDataServiceName())))
		throw new ServletException("Expected to find service path /"
				+ D2RServer.getDataServiceName());
	String serviceStem = request.getServletPath().substring(1,
			servicePos + 1);

	String resourceURI = RequestParamHandler
			.removeOutputRequestParam(server.resourceBaseURI(serviceStem)
					+ relativeResourceURI);
	String documentURL = server.dataURL(serviceStem, relativeResourceURI);

	String pageURL = server.pageURL(serviceStem, relativeResourceURI);

	String sparqlQuery = "DESCRIBE <" + resourceURI + ">";
	QueryExecution qe = QueryExecutionFactory.create(sparqlQuery,
			server.dataset());
	if (server.getConfig().getPageTimeout() > 0) {
		qe.setTimeout(Math.round(server.getConfig().getPageTimeout() * 1000));
	}
	Model description = qe.execDescribe();
	qe.close();
	
	if (description.size() == 0) {
		response.sendError(404);
	}
	if (description.qnameFor(FOAF.primaryTopic.getURI()) == null
			&& description.getNsPrefixURI("foaf") == null) {
		description.setNsPrefix("foaf", FOAF.NS);
	}
	Resource resource = description.getResource(resourceURI);

	Resource document = description.getResource(documentURL);
	document.addProperty(FOAF.primaryTopic, resource);

	Statement label = resource.getProperty(RDFS.label);
	if (label != null) {
		document.addProperty(RDFS.label,
				"RDF Description of " + label.getString());
	}
	server.addDocumentMetadata(description, document);
	if (server.getConfig().serveMetadata()) {
		// add document metadata from template
		Model resourceMetadataTemplate = server.getConfig().getResourceMetadataTemplate(
				server, getServletContext());
		MetadataCreator resourceMetadataCreator = new MetadataCreator(
				server, resourceMetadataTemplate);
		description.add(resourceMetadataCreator.addMetadataFromTemplate(
				resourceURI, documentURL, pageURL));
		
		Map<String, String> descPrefixes = description.getNsPrefixMap();
		descPrefixes.putAll(resourceMetadataTemplate.getNsPrefixMap());
		description.setNsPrefixes(descPrefixes);
	}
	// TODO: Add a Content-Location header
	new ModelResponse(description, request, response).serve();
}
 
Example 7
Source File: ResourcesUri.java    From EventCoreference with Apache License 2.0 4 votes vote down vote up
static public void prefixModelGaf (Model model) {
     model.setNsPrefix("grasp", ResourcesUri.grasp);
    model.setNsPrefix("graspAttribution", ResourcesUri.graspAttribution);
    model.setNsPrefix("graspSentiment", ResourcesUri.graspSentiment);
    model.setNsPrefix("prov", ResourcesUri.prov);
}