<commit_before># 
#    Portions Copyright (c) 2011 Talis Inc, Some Rights Reserved
# 
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
# 
#        http://www.apache.org/licenses/LICENSE-2.0
# 
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

@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 dc:<http://purl.org/dc/elements/1.1/>.
@prefix dcterms:<http://purl.org/dc/terms/>.
@prefix prov:<http://www.w3.org/ns/prov#>.
@prefix foaf:<http://xmlns.com/foaf/0.1/>.
@prefix msg:<http://www.openrdf.org/rdf/2011/messaging#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix :<#>.

<> a <SchemaGraph>;
    foaf:primaryTopic <Creatable>.

<Creatable> a owl:Class;
    rdfs:label "Creatable";
    rdfs:subClassOf <Serviceable>;
    owl:equivalentClass </callimachus/Creatable>;
    rdfs:isDefinedBy <../../ontology>.

:DeleteCreatable owl:intersectionOf ( <editable.ttl#DeleteIfNotUsed>
        [owl:onProperty msg:target; owl:allValuesFrom [owl:intersectionOf (<Editable> <Creatable>)]]);
    calli:method "DELETE";
    calli:query "edit", "describe";
    calli:requires calli:editor;
    calli:type "message/x-response";
    calli:imports <java:org.callimachusproject.server.exceptions.Conflict>;
    calli:script """
        if (this.HasInstanceChildren())
            throw new Conflict("Members of " + this + " must be deleted first");
        return proceed();
    """.

:HasInstanceChildren rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:literal; owl:allValuesFrom xsd:boolean];
    rdfs:subClassOf [owl:onProperty msg:literal; owl:cardinality 1];
    msg:sparql """
        PREFIX calli:<http://callimachusproject.org/rdf/2009/framework#>
        ASK {
            ?child a $this
        }
    """.

:GetCreatePage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:rel "create-form";
    calli:method "GET";
    calli:query "create";
    calli:requires calli:author;
    calli:type "text/html";
    calli:imports <java:org.callimachusproject.server.exceptions.InternalServerError>;
    calli:script """
        if (!this.calliCreate || this.calliCreate.isEmpty())
            throw new InternalServerError("No create template");
        if (this.calliCreate.size() != 1)
            throw new InternalServerError("Multiple create templates");
        var page = this.calliCreate.iterator().next();
        var stream = page.openInputStream();
        if (!stream)
            throw new InternalServerError(page + " does not exist");
        try {
            return this.TransformCreatePage(page, stream, targetOfCreate);
        } finally {
            stream.close();
        }
    """.

:targetOfCreate a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :GetCreatePage.

:TransformCreatePage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:post "../pipelines/creatable-html.xpl?results&target={targetOfHtml}\nContent-Location: {+createPage}\nContent-Type: application/xhtml+xml".

:createPage a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :TransformCreatePage.

:createPageStream a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :TransformCreatePage;
    rdfs:range <java:java.io.InputStream>;
    calli:type "application/xhtml+xml".

:targetOfHtml a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :TransformCreatePage.

# POST ?create=/callimachus/File
:LookupConstructor rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <Creatable>];
    msg:sparql """
        PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
        PREFIX calli:<http://callimachusproject.org/rdf/2009/framework#>
        SELECT REDUCED ?class {
            {
                # non-xml type or xml type with correct document tag
                ?class rdfs:subClassOf+ $this; calli:mediaType $mediaType
                FILTER (!bound($documentTag) || EXISTS { ?class calli:documentTag $documentTag })
                BIND (1 AS ?preference)
            } UNION {
                # supported media type alias (document tag not considered)
                ?class rdfs:subClassOf+ $this; calli:mediaType ?typ2
                FILTER (
                    (
                        (sameTerm($mediaType,"application/javascript") || sameTerm($mediaType,"text/javascript"))
                        && (sameTerm(?typ2,"application/javascript") || sameTerm(?typ2,"text/javascript"))
                    ) || (
                        (sameTerm($mediaType,"application/xslt+xml") || sameTerm($mediaType,"text/xsl"))
                        && (sameTerm(?typ2,"application/xslt+xml") || sameTerm(?typ2,"text/xsl"))
                    ) || (
                        (sameTerm($mediaType,"image/x-png") || sameTerm($mediaType,"image/png"))
                        && (sameTerm(?typ2,"image/x-png") || sameTerm(?typ2,"image/png"))
                    ) || (
                        (sameTerm($mediaType,"image/pjpeg") || sameTerm($mediaType,"image/jpeg"))
                        && (sameTerm(?typ2,"image/pjpeg") || sameTerm(?typ2,"image/jpeg"))
                    )
                )
                BIND (2 AS ?preference)
            } UNION {
                # boot strap graphs before calli:mediaType triples are loaded
                BIND (<GraphDocument> AS ?class)
                FILTER sameTerm($mediaType,"text/turtle")
                FILTER sameTerm($this, <File>)
                BIND (3 AS ?preference)
            } UNION {
                BIND ($this AS ?class)
                BIND (4 AS ?preference)
            }
        } ORDER BY ?preference LIMIT 1
    """.

:documentTag a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :LookupConstructor;
    calli:type "text/uri-list".

:mediaType a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :LookupConstructor;
    rdfs:range xsd:string.

# override this method for subclass create methods
:PostCreate rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <Serviceable>];
    calli:imports <java:org.callimachusproject.server.exceptions.InternalServerError>;
    calli:imports <java:org.callimachusproject.server.exceptions.UnsupportedMediaType>;
    calli:script """
        var template = this.calliCreate.iterator().next();
        if (!template)
            throw new InternalServerError("Cannot create " + this.toString() + " with " + type);
        if (type != "application/rdf+xml" && type.indexOf("application/rdf+xml;") != 0
                && type != "text/turtle" && type.indexOf("text/turtle;") != 0)
            throw new UnsupportedMediaType("File format is not recognized: " + type + " for " + location);
        var newCopy = template.calliCreateResource(body, type, this.toString(), location);
        newCopy = newCopy.objectConnection.addDesignation(newCopy, this.toString());
        return newCopy;
    """.<commit_msg>Reset class index page when new instance is created<commit_after># 
#    Portions Copyright (c) 2011 Talis Inc, Some Rights Reserved
# 
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
# 
#        http://www.apache.org/licenses/LICENSE-2.0
# 
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

@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 dc:<http://purl.org/dc/elements/1.1/>.
@prefix dcterms:<http://purl.org/dc/terms/>.
@prefix prov:<http://www.w3.org/ns/prov#>.
@prefix foaf:<http://xmlns.com/foaf/0.1/>.
@prefix msg:<http://www.openrdf.org/rdf/2011/messaging#>.
@prefix calli:<http://callimachusproject.org/rdf/2009/framework#>.
@prefix :<#>.

<> a <SchemaGraph>;
    foaf:primaryTopic <Creatable>.

<Creatable> a owl:Class;
    rdfs:label "Creatable";
    rdfs:subClassOf <Serviceable>;
    owl:equivalentClass </callimachus/Creatable>;
    rdfs:isDefinedBy <../../ontology>.

:DeleteCreatable owl:intersectionOf ( <editable.ttl#DeleteIfNotUsed>
        [owl:onProperty msg:target; owl:allValuesFrom [owl:intersectionOf (<Editable> <Creatable>)]]);
    calli:method "DELETE";
    calli:query "edit", "describe";
    calli:requires calli:editor;
    calli:type "message/x-response";
    calli:imports <java:org.callimachusproject.server.exceptions.Conflict>;
    calli:script """
        if (this.HasInstanceChildren())
            throw new Conflict("Members of " + this + " must be deleted first");
        return proceed();
    """.

:HasInstanceChildren rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:literal; owl:allValuesFrom xsd:boolean];
    rdfs:subClassOf [owl:onProperty msg:literal; owl:cardinality 1];
    msg:sparql """
        PREFIX calli:<http://callimachusproject.org/rdf/2009/framework#>
        ASK {
            ?child a $this
        }
    """.

:GetCreatePage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:rel "create-form";
    calli:method "GET";
    calli:query "create";
    calli:requires calli:author;
    calli:type "text/html";
    calli:imports <java:org.callimachusproject.server.exceptions.InternalServerError>;
    calli:script """
        if (!this.calliCreate || this.calliCreate.isEmpty())
            throw new InternalServerError("No create template");
        if (this.calliCreate.size() != 1)
            throw new InternalServerError("Multiple create templates");
        var page = this.calliCreate.iterator().next();
        var stream = page.openInputStream();
        if (!stream)
            throw new InternalServerError(page + " does not exist");
        try {
            return this.TransformCreatePage(page, stream, targetOfCreate);
        } finally {
            stream.close();
        }
    """.

:targetOfCreate a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :GetCreatePage.

:TransformCreatePage rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <java:java.io.Reader>];
    calli:post "../pipelines/creatable-html.xpl?results&target={targetOfHtml}\nContent-Location: {+createPage}\nContent-Type: application/xhtml+xml".

:createPage a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :TransformCreatePage.

:createPageStream a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :TransformCreatePage;
    rdfs:range <java:java.io.InputStream>;
    calli:type "application/xhtml+xml".

:targetOfHtml a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :TransformCreatePage.

# POST ?create=/callimachus/File
:LookupConstructor rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <Creatable>];
    msg:sparql """
        PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
        PREFIX calli:<http://callimachusproject.org/rdf/2009/framework#>
        SELECT REDUCED ?class {
            {
                # non-xml type or xml type with correct document tag
                ?class rdfs:subClassOf+ $this; calli:mediaType $mediaType
                FILTER (!bound($documentTag) || EXISTS { ?class calli:documentTag $documentTag })
                BIND (1 AS ?preference)
            } UNION {
                # supported media type alias (document tag not considered)
                ?class rdfs:subClassOf+ $this; calli:mediaType ?typ2
                FILTER (
                    (
                        (sameTerm($mediaType,"application/javascript") || sameTerm($mediaType,"text/javascript"))
                        && (sameTerm(?typ2,"application/javascript") || sameTerm(?typ2,"text/javascript"))
                    ) || (
                        (sameTerm($mediaType,"application/xslt+xml") || sameTerm($mediaType,"text/xsl"))
                        && (sameTerm(?typ2,"application/xslt+xml") || sameTerm(?typ2,"text/xsl"))
                    ) || (
                        (sameTerm($mediaType,"image/x-png") || sameTerm($mediaType,"image/png"))
                        && (sameTerm(?typ2,"image/x-png") || sameTerm(?typ2,"image/png"))
                    ) || (
                        (sameTerm($mediaType,"image/pjpeg") || sameTerm($mediaType,"image/jpeg"))
                        && (sameTerm(?typ2,"image/pjpeg") || sameTerm(?typ2,"image/jpeg"))
                    )
                )
                BIND (2 AS ?preference)
            } UNION {
                # boot strap graphs before calli:mediaType triples are loaded
                BIND (<GraphDocument> AS ?class)
                FILTER sameTerm($mediaType,"text/turtle")
                FILTER sameTerm($this, <File>)
                BIND (3 AS ?preference)
            } UNION {
                BIND ($this AS ?class)
                BIND (4 AS ?preference)
            }
        } ORDER BY ?preference LIMIT 1
    """.

:documentTag a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :LookupConstructor;
    calli:type "text/uri-list".

:mediaType a owl:FunctionalProperty, owl:ObjectProperty;
    rdfs:domain :LookupConstructor;
    rdfs:range xsd:string.

# override this method for subclass create methods
:PostCreate rdfs:subClassOf msg:Message;
    rdfs:subClassOf [owl:onProperty msg:target; owl:allValuesFrom <Creatable>];
    rdfs:subClassOf [owl:onProperty msg:object; owl:allValuesFrom <Serviceable>];
    calli:imports <java:org.callimachusproject.server.exceptions.InternalServerError>;
    calli:imports <java:org.callimachusproject.server.exceptions.UnsupportedMediaType>;
    calli:script """
        var template = this.calliCreate.iterator().next();
        if (!template)
            throw new InternalServerError("Cannot create " + this.toString() + " with " + type);
        if (type != "application/rdf+xml" && type.indexOf("application/rdf+xml;") != 0
                && type != "text/turtle" && type.indexOf("text/turtle;") != 0)
            throw new UnsupportedMediaType("File format is not recognized: " + type + " for " + location);
        var newCopy = template.calliCreateResource(body, type, this.toString(), location);
        newCopy = newCopy.objectConnection.addDesignation(newCopy, this.toString());
        this.touchRevision(); // FIXME this shouldn't be needed
        return newCopy;
    """.
{'fraction_non_alphanumeric': 0.13378810226155358, 'fraction_numerical': 0.010939036381514257, 'mean_word_length': 3.0170328313996544, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 18, 'xml': 18}, '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': '6689038', 'n_tokens_mistral': 5278, 'n_tokens_neox': 4907, 'n_words': 1002}