License discovery service for RDF documents

This post describes a service to discover the license in a RDF file (ontology, dataset, etc.).

The service is available by providing the URI (see Service #1 at http://licensius.appspot.com) but it is also provided as a RESTful service, very easy to be invoked:

The name of the service is as follows:

http://licensius.appspot.com/getLicense

The only parameter is the parameter "content", with the URI duely encoded. You can for example type this in your web browser:

http://licensius.appspot.com/getLicense?content=http%3A%2F%2Fpurl.org%2Fgoodrelations%2Fv1.owl

If your prefer to invoke the service from java, you can simply type this:

public static void main(String[] args) {
	String license=getLicense("http://purl.org/net/p-plan");
	System.out.println(license);
}

/**
 * Invokes the getLicense method of the Licensius service, so that
 * the license in a RDF resource is found.
 * @param uriToScan URI to scan, for example http://purl.org/goodrelations/v1.owl
 */
public static String getLicense(String uriToScan) {
	String output="unknown";
	try {
		String uri="http://licensius.appspot.com/getLicense?content=";
		String encodedData = URLEncoder.encode(uriToScan);
		uri+=encodedData;
		System.out.println(uri);
		URL url = new URL(uri);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setDoOutput(true);
		conn.setRequestMethod("GET");
		conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");            
		conn.setRequestProperty("Content-Length", String.valueOf(encodedData.length()));
		if (conn.getResponseCode() != 200) {
		 throw new RuntimeException("HTTP error code : "+ conn.getResponseCode());
		}
		BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
		String linea = "";
		while ((linea = br.readLine()) != null) {
			output=linea;
		}
		conn.disconnect();
	} catch (Exception e) {
		e.printStackTrace();
	} 
	return output;
}

The biggest concern is how to distinguish whether a detected licensing triple is qualifying the whole document (ontology / dataset) or not.
This is a problem for non-obvious cases (VoID described resources), but the problem is not exclusive of the licensing metadata information...

Late hint: if you want to know the title and a RDF version of the license, just declare that you want JSON

conn.setRequestProperty("Accept", "application/json");

and then you will get an structured answer...

{"title":"Creative Commons CC-BY 3.0","rdf":"http://purl.org/NET/rdflicense/cc-by3.0","uri":"http://creativecommons.org/licenses/by/3.0/"}

Tags:

.: