<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 obj:<http://www.openrdf.org/rdf/2009/object#>.
@prefix http:<http://www.openrdf.org/rdf/2009/httpobject#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix purl:<http://persistent.name/rdf/2010/purl#>.

################################
# Realm
################################

<anybody> a calli:AnybodyRealm;
	calli:origin </>;
	calli:domain </>.

<local> a calli:LocalRealm;
	calli:origin </>;
	calli:domain </>;
	calli:forbidden <forbidden.xml>.

<authority> a calli:DigestRealm;
	calli:origin </>;
	calli:authName </>;
	calli:domain </>;
	calli:unauthorized <unauthorized.xml>;
	calli:forbidden <forbidden.xml>.

calli:SPARQLService http:realm <local>.
calli:describe http:realm <local>.
calli:get-graph http:realm <local>.

calli:get-copy http:realm <authority>.
calli:post-copy http:realm <authority>.
calli:get-edit http:realm <authority>.
calli:post-edit http:realm <authority>.
calli:get-delete http:realm <authority>.
calli:post-delete http:realm <authority>.

################################
# User
################################

purl:User rdfs:subClassOf calli:Credential;
	http:realm <authority>.

purl:email a owl:DatatypeProperty, owl:FunctionalProperty;
	rdfs:domain purl:User;
	rdfs:range xsd:string.

rdfs:label a owl:DatatypeProperty;
	rdfs:range xsd:string;
	http:method "GET";
	http:operation "label";
	http:type "text/plain;q=0.9";
	http:rel "alternate".

purl:purl-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject a purl:PURL; purl:partOf ?partial
			{
				?partial calli:scribe $credential
				FILTER ($qs = "copy")
			} UNION {
				?partial calli:curator $credential
			} UNION {
				?partial calli:maintainer $credential
			} UNION {
				?partial purl:belongsTo [calli:scribe $credential]
				FILTER ($qs = "copy")
			} UNION {
				?partial purl:belongsTo [calli:curator $credential]
			} UNION {
				?partial purl:belongsTo [calli:maintainer $credential]
			}
			OPTIONAL {
				{
					?partial a ?mirror
				} UNION {
					?partial purl:belongsTo [a ?mirror]
				}
				FILTER (?mirror = purl:MirroredDomain)
			}
			FILTER (!bound(?mirror))
		}
	""".

purl:partial-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject a purl:Partial; purl:belongsTo ?domain
			{
				?domain calli:scribe $credential
				FILTER ($qs = "copy" || $qs = "purl-create" || $qs = "partial-create")
			} UNION {
				?domain calli:curator $credential
				FILTER ($qs = "edit" || $qs = "copy" || $qs = "purl-create" || $qs = "partial-create" || $qs = "purl-disable" || $qs = "purl-enable" || $qs = "purl-tombstone")
			} UNION {
				?domain calli:maintainer $credential
				FILTER ($qs = "edit" || $qs = "copy" || $qs = "purl-create" || $qs = "partial-create" || $qs = "domain-create" || $qs = "purl-disable" || $qs = "purl-enable" || $qs = "purl-tombstone")
			}
			OPTIONAL { ?domain a ?mirror FILTER (?mirror = purl:MirroredDomain) }
			FILTER (!bound(?mirror))
		}
	""".

purl:domain-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject a purl:Domain
			{
				$subject calli:scribe $credential
			} UNION {
				$subject calli:curator $credential
			}
			FILTER ($qs = "purl-create" || $qs = "partial-create")
			OPTIONAL { $subject a ?mirror FILTER (?mirror = purl:MirroredDomain) }
			FILTER (!bound(?mirror))
		}
	""".

purl:login-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject calli:credential $credential
			FILTER ($method = "GET" || $method = "HEAD")
			FILTER ($qs = "login")
		}
	""".

# Prompts the browser to login using different credentials
# Available to user when logged in
purl:logout rdfs:subClassOf obj:Message;
	rdfs:subClassOf [owl:onProperty obj:target;
		owl:allValuesFrom calli:DigestRealm];
	rdfs:subClassOf [owl:onProperty obj:functionalObjectResponse;
		owl:allValuesFrom <java:org.apache.http.HttpResponse>];
	http:operation "logout";
	http:cache-control "private";
	http:type "message/x-response";
	obj:imports <java:org.apache.http.ProtocolVersion>;
	obj:imports <java:org.apache.http.message.BasicHttpResponse>;
	obj:groovy """
		def ver = new ProtocolVersion("HTTP", 1, 1)
		def resp = new BasicHttpResponse(ver, 303, "See Other")
		def credential = findCredential(msg.authorization)
		if (credential == null) {
			resp.setHeader("Location", toString() + "?login")
			return resp
		}
		if (msg.user != null && msg.user == credential)
			return unauthorized()
		if (msg.user == null) {
			resp.setHeader("Location", toString() + "?logout&from=" + credential.toString())
		} else {
			resp.setHeader("Location", credential.toString())
		}
		return resp
	""".

purl:logout-authorization a owl:DatatypeProperty, owl:FunctionalProperty;
	rdfs:domain purl:logout;
	rdfs:range xsd:string;
	http:header "Authorization";
	obj:name "authorization".

purl:logout-user a owl:ObjectProperty, owl:FunctionalProperty;
	rdfs:domain purl:logout;
	rdfs:range calli:Credential;
	http:parameter "from";
	http:type "text/uri-list";<commit_msg>Fix logout link<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 obj:<http://www.openrdf.org/rdf/2009/object#>.
@prefix http:<http://www.openrdf.org/rdf/2009/httpobject#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix purl:<http://persistent.name/rdf/2010/purl#>.

################################
# Realm
################################

<anybody> a calli:AnybodyRealm;
	calli:origin </>;
	calli:domain </>.

<local> a calli:LocalRealm;
	calli:origin </>;
	calli:domain </>;
	calli:forbidden <forbidden.xml>.

<authority> a calli:DigestRealm;
	calli:origin </>;
	calli:authName </>;
	calli:domain </>;
	calli:unauthorized <unauthorized.xml>;
	calli:forbidden <forbidden.xml>.

calli:SPARQLService http:realm <local>.
calli:describe http:realm <local>.
calli:get-graph http:realm <local>.

calli:get-copy http:realm <authority>.
calli:post-copy http:realm <authority>.
calli:get-edit http:realm <authority>.
calli:post-edit http:realm <authority>.
calli:get-delete http:realm <authority>.
calli:post-delete http:realm <authority>.

################################
# User
################################

purl:User rdfs:subClassOf calli:Credential;
	http:realm <authority>.

purl:email a owl:DatatypeProperty, owl:FunctionalProperty;
	rdfs:domain purl:User;
	rdfs:range xsd:string.

rdfs:label a owl:DatatypeProperty;
	rdfs:range xsd:string;
	http:method "GET";
	http:operation "label";
	http:type "text/plain;q=0.9";
	http:rel "alternate".

purl:purl-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject a purl:PURL; purl:partOf ?partial
			{
				?partial calli:scribe $credential
				FILTER ($qs = "copy")
			} UNION {
				?partial calli:curator $credential
			} UNION {
				?partial calli:maintainer $credential
			} UNION {
				?partial purl:belongsTo [calli:scribe $credential]
				FILTER ($qs = "copy")
			} UNION {
				?partial purl:belongsTo [calli:curator $credential]
			} UNION {
				?partial purl:belongsTo [calli:maintainer $credential]
			}
			OPTIONAL {
				{
					?partial a ?mirror
				} UNION {
					?partial purl:belongsTo [a ?mirror]
				}
				FILTER (?mirror = purl:MirroredDomain)
			}
			FILTER (!bound(?mirror))
		}
	""".

purl:partial-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject a purl:Partial; purl:belongsTo ?domain
			{
				?domain calli:scribe $credential
				FILTER ($qs = "copy" || $qs = "purl-create" || $qs = "partial-create")
			} UNION {
				?domain calli:curator $credential
				FILTER ($qs = "edit" || $qs = "copy" || $qs = "purl-create" || $qs = "partial-create" || $qs = "purl-disable" || $qs = "purl-enable" || $qs = "purl-tombstone")
			} UNION {
				?domain calli:maintainer $credential
				FILTER ($qs = "edit" || $qs = "copy" || $qs = "purl-create" || $qs = "partial-create" || $qs = "domain-create" || $qs = "purl-disable" || $qs = "purl-enable" || $qs = "purl-tombstone")
			}
			OPTIONAL { ?domain a ?mirror FILTER (?mirror = purl:MirroredDomain) }
			FILTER (!bound(?mirror))
		}
	""".

purl:domain-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject a purl:Domain
			{
				$subject calli:scribe $credential
			} UNION {
				$subject calli:curator $credential
			}
			FILTER ($qs = "purl-create" || $qs = "partial-create")
			OPTIONAL { $subject a ?mirror FILTER (?mirror = purl:MirroredDomain) }
			FILTER (!bound(?mirror))
		}
	""".

purl:login-authorize owl:equivalentClass calli:authorize-credential;
	obj:sparql """
		ASK {
			$subject calli:credential $credential
			FILTER ($method = "GET" || $method = "HEAD")
			FILTER ($qs = "login")
		}
	""".

# Prompts the browser to login using different credentials
# Available to user when logged in
purl:logout rdfs:subClassOf obj:Message;
	rdfs:subClassOf [owl:onProperty obj:target;
		owl:allValuesFrom calli:DigestRealm];
	rdfs:subClassOf [owl:onProperty obj:functionalObjectResponse;
		owl:allValuesFrom <java:org.apache.http.HttpResponse>];
	http:operation "logout";
	http:cache-control "private";
	http:type "message/x-response";
	obj:imports <java:org.apache.http.ProtocolVersion>;
	obj:imports <java:org.apache.http.message.BasicHttpResponse>;
	obj:groovy """
		def ver = new ProtocolVersion("HTTP", 1, 1)
		def resp = new BasicHttpResponse(ver, 303, "See Other")
		def credential = findCredential(msg.authorization)
		if (credential == null) {
			resp.setHeader("Location", toString() + "?login")
			return resp
		}
		if (msg.user != null && msg.user == credential)
			return unauthorized(credential)
		if (msg.user == null) {
			resp.setHeader("Location", toString() + "?logout&from=" + credential.toString())
		} else {
			resp.setHeader("Location", credential.toString())
		}
		return resp
	""".

purl:logout-authorization a owl:DatatypeProperty, owl:FunctionalProperty;
	rdfs:domain purl:logout;
	rdfs:range xsd:string;
	http:header "Authorization";
	obj:name "authorization".

purl:logout-user a owl:ObjectProperty, owl:FunctionalProperty;
	rdfs:domain purl:logout;
	rdfs:range calli:Credential;
	http:parameter "from";
	http:type "text/uri-list";
{'fraction_non_alphanumeric': 0.1816122333396262, 'fraction_numerical': 0.009628091372474987, 'mean_word_length': 4.644645711241343, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 6}, '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': '3846580', 'n_tokens_mistral': 4309, 'n_tokens_neox': 3890, 'n_words': 737}