Java Code Examples for org.openrdf.rio.RDFFormat#TURTLE

The following examples show how to use org.openrdf.rio.RDFFormat#TURTLE . 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 check out the related API usage on the sidebar.
Example 1
/**
 * Loads all triples found in the datafile associated with the given name.
 * 
 * @param datafileName the name of the datafile.
 * @param graphs an optional set of target graph URIs. 
 * @throws Exception hopefully never, otherwise the test fails.
 */
protected void load(final MisteryGuest data) throws Exception {
	if (data.datasets == null || data.datasets.length == 0) {
		return;
	}
	
	for (final String datafileName : data.datasets) {
		final RDFFormat format = datafileName.endsWith(".ttl") ? RDFFormat.TURTLE : RDFFormat.RDFXML;
		if (data.graphURI != null) {
			localConnection.add(source(datafileName), DUMMY_BASE_URI, format, localConnection.getValueFactory().createURI(data.graphURI));
			cumulusConnection.add(source(datafileName), DUMMY_BASE_URI, format, cumulusConnection.getValueFactory().createURI(data.graphURI));
		} else {
			localConnection.add(source(datafileName), DUMMY_BASE_URI, format);
			cumulusConnection.add(source(datafileName), DUMMY_BASE_URI, format);				
		}
	}  
}
 
Example 2
private static RDFFormat guessFormatFromName(String name) {
    if (name.endsWith(".ttl")) {
        return RDFFormat.TURTLE;
    } else if (name.endsWith(".xml")) {
        return RDFFormat.RDFXML;
    }
    return RDFFormat.RDFXML;
}
 
Example 3
/**
 * Returns an instance of {@link org.openrdf.rio.RDFFormat} for a
 * given MIME-Type string.
 *
 * @param mimetype the MIME-Type as string
 * @return the corresponding RDF-Format
 */
protected RDFFormat getRDFFormat(String mimetype) {
	switch (mimetype) {
		default:
		case RDFMediaType.RDF_TURTLE:
			return RDFFormat.TURTLE;
		case RDFMediaType.RDF_XML:
			return RDFFormat.RDFXML;
		case RDFMediaType.RDF_NTRIPLES:
			return RDFFormat.NTRIPLES;
		case RDFMediaType.RDF_JSON:
			return RDFFormat.RDFJSON;
	}
}
 
Example 4
Source Project: mustard   File: SubsetDataSet.java    License: MIT License 5 votes vote down vote up
public SubsetDataSet(String dir) {
	tripleStore = new RDFFileDataSet(dir + "/subset.ttl", RDFFormat.TURTLE);
	instances = new ArrayList<Resource>();
	target = new ArrayList<Double>();
	
	try {
		BufferedReader instReader = new BufferedReader(new FileReader(dir + "/instances.txt"));

		String line = instReader.readLine();
		while (line != null) {
			instances.add(tripleStore.createURI(line));
			line = instReader.readLine();
		}
		instReader.close();
		
		BufferedReader targetReader = new BufferedReader(new FileReader(dir + "/target.txt"));

		line = targetReader.readLine();
		while (line != null) {
			target.add(Double.parseDouble(line));
			line = targetReader.readLine();
		}
		targetReader.close();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 5
Source Project: ldp4j   File: TurtlePrettyPrinter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public RDFFormat getRDFFormat() {
	return RDFFormat.TURTLE;
}
 
Example 6
Source Project: mustard   File: FeatureCountAMExperiment.java    License: MIT License 2 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {

	dataset = new RDFFileDataSet(AM_FOLDER, RDFFormat.TURTLE);

	long[] seedsDataset = {11,21,31,41,51}; //,61,71,81,91,101};

	int[] subsetSize = {100, 200, 400, 800};



	for (int ss : subsetSize) {
		double avgInstances = 0;
		double avgNumFeatures = 0;
		double avgNonZeroFeatures = 0;
		for (long sDS : seedsDataset) {
			createAMDataSet(dataset, sDS, ss, 10);
			RDFData data = new RDFData(dataset, instances, blackList);
			RDFWLSubTreeKernel kernel = new RDFWLSubTreeKernel(4, 2, false, true, false, true);
			SparseVector[] fv = kernel.computeFeatureVectors(data);
			
			avgInstances += fv.length;
			avgNumFeatures += fv[0].getLastIndex()+1;
			double avg = 0;
			for (SparseVector v : fv) {
				avg += v.size();
			}
			avgNonZeroFeatures += (avg / (fv.length));
		}
		
		avgInstances /= (seedsDataset.length);
		avgNumFeatures /= (seedsDataset.length);
		avgNonZeroFeatures /= (seedsDataset.length);
		
		System.out.println("# instances: " + avgInstances + ", # features: " + avgNumFeatures +  ", # non-zero features: " + avgNonZeroFeatures);
	}





}