<commit_before>@prefix xsd:<http://www.w3.org/2001/XMLSchema#>.
@prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl:<http://www.w3.org/2002/07/owl#>.
@prefix skos:<http://www.w3.org/2004/02/skos/core#>.
@prefix msg:<http://www.openrdf.org/rdf/2011/messaging#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix audit:<http://www.openrdf.org/rdf/2009/auditing#>.
@prefix :<#>.

<> a <../SchemaGraph>.

:LookupAndGo rdfs:subClassOf msg:Message;
	rdfs:subClassOf [owl:onProperty msg:target; owl:hasValue <../go>];
	rdfs:subClassOf [owl:onProperty msg:literal; owl:allValuesFrom xsd:string];
	calli:method "GET";
	calli:expect "302-see-other";
	calli:header "cache-control:no-store";
	msg:imports <java:org.openrdf.model.vocabulary.RDFS>;
	msg:imports <java:org.openrdf.model.vocabulary.RDF>;
	msg:imports <java:java.net.URLEncoder>;
	msg:imports <../lookup>;
	msg:imports </diverted>;
	msg:imports calli:Viewable;
	msg:script """
		var con = this.objectConnection;
		var vf = con.valueFactory;

		function canonicalize(uri) {
			uri = uri.normalize();
			var sch = uri.scheme.toLowerCase();
			var frag = uri.fragment;
			if (uri.isOpaque()) {
				return new java.net.URI(sch, uri.schemeSpecificPart, frag);
			} else {
				var auth = uri.authority.toLowerCase();
				return new java.net.URI(sch, auth, uri.path, uri.query, frag);
			}
		}

		function parseAbsoluteURI(string) {
			try {
				if (string.indexOf(":") > 0) {
					var uri = java.net.URI.create(string);
					if (uri.isAbsolute())
						return canonicalize(uri);
				} else if (string.indexOf("/") == 0) {
					var origin = java.net.URI.create(lookup.toString());
					var sch = origin.scheme;
					var auth = origin.authority;
					var uri = java.net.URI.create(string);
					var frag = uri.fragment;
					uri = new java.net.URI(sch, auth, uri.path, uri.query, frag);
					return canonicalize(uri);
				}
			} catch (e) {
				return null;
			}
		}

		function redirectURL(uri) {
			var origin = uri.authority ? new java.net.URI(uri.scheme, uri.authority, "/", null, null).toString() : null;
			var iri = uri.toString();
			var viewable = con.getObject(iri) instanceof Viewable;
			var Origin = vf.createURI("http://callimachusproject.org/rdf/2009/framework#Origin");
			var authority = origin && con.hasStatement(vf.createURI(origin), RDF.TYPE, Origin, []);
			if (viewable && authority && (uri.query || uri.fragment)) { //# complex resource URI
				var url = origin + "diverted;" + URLEncoder.encode(iri) + '?view';
				return url;
			} else if (viewable && authority) { //# Self resolving URL
				var url = iri + '?view';
				return url;
			} else if (viewable) { //# Foreign IRI, but can be presented here
				var url = diverted.toString() + ";" + URLEncoder.encode(iri) + '?view';
				return url;
			} else { //# Unknown resource
				return iri;
			}
		}

		var uri = parseAbsoluteURI(q);
		if (uri) { //# absolute URI redirect
			return redirectURL(uri);
		}
		var stmts = con.getStatements(null, null, vf.createLiteral(q), []);
		try { //# check if there is a resource with this exact label
			if (stmts.hasNext()) {
				var st = stmts.next();
				var uri = st.subject;
				var pred = st.predicate;
				if (uri instanceof org.openrdf.model.URI && !stmts.hasNext()
						&& (RDFS.LABEL.equals(pred)
						|| pred.stringValue().equals("http://www.w3.org/2004/02/skos/core#prefLabel")
						|| pred.stringValue().equals("http://xmlns.com/foaf/0.1/name")
						|| pred.stringValue().equals("http://www.w3.org/2008/05/skos-xl#literalForm")))
					return redirectURL(java.net.URI.create(uri.stringValue()));
			}
		} finally {
			stmts.close();
		}
		return lookup + "?q=" + URLEncoder.encode(q); //# list resources by label prefix
	""".<commit_msg>Handle null<commit_after>@prefix xsd:<http://www.w3.org/2001/XMLSchema#>.
@prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl:<http://www.w3.org/2002/07/owl#>.
@prefix skos:<http://www.w3.org/2004/02/skos/core#>.
@prefix msg:<http://www.openrdf.org/rdf/2011/messaging#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix audit:<http://www.openrdf.org/rdf/2009/auditing#>.
@prefix :<#>.

<> a <../SchemaGraph>.

:LookupAndGo rdfs:subClassOf msg:Message;
	rdfs:subClassOf [owl:onProperty msg:target; owl:hasValue <../go>];
	rdfs:subClassOf [owl:onProperty msg:literal; owl:allValuesFrom xsd:string];
	calli:method "GET";
	calli:expect "302-see-other";
	calli:header "cache-control:no-store";
	msg:imports <java:org.openrdf.model.vocabulary.RDFS>;
	msg:imports <java:org.openrdf.model.vocabulary.RDF>;
	msg:imports <java:java.net.URLEncoder>;
	msg:imports <../lookup>;
	msg:imports </diverted>;
	msg:imports calli:Viewable;
	msg:script """
		var con = this.objectConnection;
		var vf = con.valueFactory;

		function canonicalize(uri) {
			uri = uri.normalize();
			var sch = uri.scheme.toLowerCase();
			var frag = uri.fragment;
			if (uri.isOpaque()) {
				return new java.net.URI(sch, uri.schemeSpecificPart, frag);
			} else {
				var auth = uri.authority.toLowerCase();
				return new java.net.URI(sch, auth, uri.path, uri.query, frag);
			}
		}

		function parseAbsoluteURI(string) {
			try {
				if (string.indexOf(":") > 0) {
					var uri = java.net.URI.create(string);
					if (uri.isAbsolute())
						return canonicalize(uri);
				} else if (string.indexOf("/") == 0) {
					var origin = java.net.URI.create(lookup.toString());
					var sch = origin.scheme;
					var auth = origin.authority;
					var uri = java.net.URI.create(string);
					var frag = uri.fragment;
					uri = new java.net.URI(sch, auth, uri.path, uri.query, frag);
					return canonicalize(uri);
				}
			} catch (e) {
				return null;
			}
		}

		function redirectURL(uri) {
			var origin = uri.authority ? new java.net.URI(uri.scheme, uri.authority, "/", null, null).toString() : null;
			var iri = uri.toString();
			var viewable = con.getObject(iri) instanceof Viewable;
			var Origin = vf.createURI("http://callimachusproject.org/rdf/2009/framework#Origin");
			var authority = origin && con.hasStatement(vf.createURI(origin), RDF.TYPE, Origin, []);
			if (viewable && authority && (uri.query || uri.fragment)) { //# complex resource URI
				var url = origin + "diverted;" + URLEncoder.encode(iri) + '?view';
				return url;
			} else if (viewable && authority) { //# Self resolving URL
				var url = iri + '?view';
				return url;
			} else if (viewable) { //# Foreign IRI, but can be presented here
				var url = diverted.toString() + ";" + URLEncoder.encode(iri) + '?view';
				return url;
			} else { //# Unknown resource
				return iri;
			}
		}

		if (!q)
			return lookup;
		var uri = parseAbsoluteURI(q);
		if (uri) { //# absolute URI redirect
			return redirectURL(uri);
		}
		var stmts = con.getStatements(null, null, vf.createLiteral(q), []);
		try { //# check if there is a resource with this exact label
			if (stmts.hasNext()) {
				var st = stmts.next();
				var uri = st.subject;
				var pred = st.predicate;
				if (uri instanceof org.openrdf.model.URI && !stmts.hasNext()
						&& (RDFS.LABEL.equals(pred)
						|| pred.stringValue().equals("http://www.w3.org/2004/02/skos/core#prefLabel")
						|| pred.stringValue().equals("http://xmlns.com/foaf/0.1/name")
						|| pred.stringValue().equals("http://www.w3.org/2008/05/skos-xl#literalForm")))
					return redirectURL(java.net.URI.create(uri.stringValue()));
			}
		} finally {
			stmts.close();
		}
		return lookup + "?q=" + URLEncoder.encode(q); //# list resources by label prefix
	""".
{'fraction_non_alphanumeric': 0.17691703742475792, 'fraction_numerical': 0.01884323475529966, 'mean_word_length': 3.4513686662783924, 'pattern_counts': {'":': 2, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 18, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4720394', 'n_tokens_mistral': 3252, 'n_tokens_neox': 2764, 'n_words': 541}