Skip to content

Commit

Permalink
w3id: fix more content negotiation
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVanAssche committed Oct 9, 2023
1 parent a6b7d80 commit 8880dd7
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 79 deletions.
72 changes: 46 additions & 26 deletions w3id/generate-w3id.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@
RewriteEngine on
DirectorySlash Off
## RML Ontology content negotiation
## RML Ontology content negotation
RewriteCond %{HTTP_ACCEPT} application/ld\\+json
RewriteRule ^(.*)\\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.json [NE,R,L]
RewriteCond %{HTTP_ACCEPT} application/n-triples
RewriteRule ^(.*)\\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.nt [NE,R,L]
RewriteCond %{HTTP_ACCEPT} application/rdf\\+xml
RewriteRule ^(.*)\\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.rdf [NE,R,L]
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^(.*)\\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.ttl [NE,R,L]
RewriteCond %{HTTP_ACCEPT} .+\n
## RML Ontology content negotiation resources
RewriteCond %{HTTP_ACCEPT} text/html
RewriteRule ^(.*)\\.(core|io|cc|fnml|star).conneg$ https://kg-construct.github.io/rml-$2/ontology/documentation/index-en.html#http://w3id.org/$1 [NE,R,L]
RewriteCond %{HTTP_ACCEPT} application/ld\\+json
Expand All @@ -25,7 +36,7 @@
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^(.*)\\.(core|io|cc|fnml|star).conneg$ https://kg-construct.github.io/rml-$2/ontology/documentation/ontology.ttl#http://w3id.org/$1 [NE,R,L]
RewriteCond %{HTTP_ACCEPT} .+\n
RewriteRule ^(.*)\\.(core|io|cc|fnml|star).conneg$ https://kg-construct.github.io/rml-resources/406.html [NE,L,R=406]
RewriteRule (.*)\\.(core|io|cc|fnml|star|resource).conneg$ https://kg-construct.github.io/rml-resources/406.html [NE,L,R=406]
"""


Expand All @@ -49,38 +60,37 @@ def extract_spec(url: str):

def template_resources(resources: List[str], spec: str):
return \
'RewriteCond %{REQUEST_URI} ^/rml/(' + '|'.join(resources) + ')$\n' \
'RewriteRule ^rml/(.*)$ /rml/$1.' + spec + '.conneg [NE,R,L]\n'

'RewriteCond %{REQUEST_URI} (' + '|'.join(resources) + ')$\n' \
'RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1.' + spec + '.conneg [NE,R,L]\n'

def template_ontology(spec: str):
return \
'RewriteCond %{REQUEST_URI} ^/rml/' + spec + '\n' \
'RewriteRule ^rml/' + spec + \
'RewriteCond %{REQUEST_URI} ' + spec + '\n' \
'RewriteRule ' + spec + \
'/?$ https://kg-construct.github.io/rml-' + spec + \
'/ontology/documentation/index-en.html [NE,R,L]'


def template_shapes(spec: str):
return \
'RewriteCond %{REQUEST_URI} ^/rml/' + spec + '/shapes\n' \
'RewriteRule ^rml/' + spec + \
'RewriteCond %{REQUEST_URI} ' + spec + '/shapes\n' \
'RewriteRule ' + spec + \
'/shapes/?$ https://kg-construct.github.io/rml-' + spec + \
'/shapes/' + spec + '.ttl [NE,R,L]'


def template_spec(spec: str):
return \
'RewriteCond %{REQUEST_URI} ^/rml/' + spec + '/spec\n' \
'RewriteRule ^rml/' + spec + \
'RewriteCond %{REQUEST_URI} ' + spec + '/spec\n' \
'RewriteRule ' + spec + \
'/spec/?$ https://kg-construct.github.io/rml-' + spec + \
'/spec/docs [NE,R,L]'


def template_bc(spec: str):
return \
'RewriteCond %{REQUEST_URI} ^/rml/' + spec + '/bc\n' \
'RewriteRule ^rml/' + spec + \
'RewriteCond %{REQUEST_URI} ' + spec + '/bc\n' \
'RewriteRule ' + spec + \
'/bc/?$ https://kg-construct.github.io/rml-' + spec + \
'/ontology/rml-' + spec + '-bc.ttl [NE,R,L]'

Expand All @@ -89,12 +99,22 @@ def template_notacceptable(resource: str, url: str, replace_from: str,
replace_to: str):
return \
'RewriteCond %{HTTP_ACCEPT} .+\n' \
f'RewriteRule ^{resource}/?$ {url.replace(replace_from, replace_to)}' \
f'RewriteRule {resource}/?$ {url.replace(replace_from, replace_to)}' \
' [NE,L,R=406]\n'


def template_redirect(resource: str, url: str):
return f'RewriteRule ^{resource}/?$ {url} [NE,L,R=301]\n'
return f'RewriteRule {resource}/?$ {url} [NE,L,R=301]\n'


def template_redirect_negotiate(resource: str, name: str, root: bool):
if root:
return \
'RewriteRule ^$ https://%{SERVER_NAME}/' + name + '.resource.conneg [NE,R,L]\n'
else:
return \
'RewriteCond %{REQUEST_URI} ' + resource + '$\n' \
'RewriteRule (.*)$ https://%{SERVER_NAME}/' + name + '.resource.conneg [NE,R,L]\n'


def read_csv():
Expand Down Expand Up @@ -161,17 +181,17 @@ def generate_htaccess(rows: list):
rules[spec].append(template_ontology(spec))
rules[spec].append(template_spec(spec))
rules[spec].append(template_shapes(spec))
elif 'rml-resources/ontology.ttl' in url or \
'rml-resources/backwards-compatibility.ttl' in url or \
'rml-resources/shapes.ttl' in url:
name = url.split('/')[-1].replace('.ttl', '')
root = False
if 'rml-resources/ontology.ttl' in url:
root = True
rules['resources'].append(template_redirect_negotiate(resource,
name, root))
elif 'rml-resources' in url:
rules['resources'].append(template_redirect('rml/' + resource,
url))
elif 'rml-resources/backwards-compatibility.ttl' in url:
pass
elif 'rml-resources/shapes.ttl' in url:
pass
elif 'rml-resources/resources' in url:
pass
elif 'rml-resources/portal' in url:
pass
rules['resources'].append(template_redirect(resource, url))
elif '-bc.ttl' in url:
spec = extract_spec(url)
rules[spec].append(template_bc(spec))
Expand All @@ -188,7 +208,7 @@ def generate_htaccess(rows: list):
for r in rules[key]:
f.write(r + '\n')
f.write('\n')
f.write('RewriteRule ^rml/(.*)$' +
f.write('RewriteRule ^(.*)$' +
' https://kg-construct.github.io/rml-resources/404.html' +
' [NE,L,R=404]\n')
f.flush()
Expand Down
120 changes: 67 additions & 53 deletions w3id/redirections.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
RewriteEngine on
DirectorySlash Off

## RML Ontology content negotiation
## RML Ontology content negotation
RewriteCond %{HTTP_ACCEPT} application/ld\+json
RewriteRule ^(.*)\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.json [NE,R,L]
RewriteCond %{HTTP_ACCEPT} application/n-triples
RewriteRule ^(.*)\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.nt [NE,R,L]
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^(.*)\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.rdf [NE,R,L]
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^(.*)\.resource.conneg$ https://kg-construct.github.io/rml-resources/$1.ttl [NE,R,L]
RewriteCond %{HTTP_ACCEPT} .+


## RML Ontology content negotiation resources
RewriteCond %{HTTP_ACCEPT} text/html
RewriteRule ^(.*)\.(core|io|cc|fnml|star).conneg$ https://kg-construct.github.io/rml-$2/ontology/documentation/index-en.html#http://w3id.org/$1 [NE,R,L]
RewriteCond %{HTTP_ACCEPT} application/ld\+json
Expand All @@ -15,80 +27,82 @@ RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^(.*)\.(core|io|cc|fnml|star).conneg$ https://kg-construct.github.io/rml-$2/ontology/documentation/ontology.ttl#http://w3id.org/$1 [NE,R,L]
RewriteCond %{HTTP_ACCEPT} .+

RewriteRule ^(.*)\.(core|io|cc|fnml|star).conneg$ https://kg-construct.github.io/rml-resources/406.html [NE,L,R=406]
RewriteRule (.*)\.(core|io|cc|fnml|star|resource).conneg$ https://kg-construct.github.io/rml-resources/406.html [NE,L,R=406]
# === RML cc ===
RewriteCond %{REQUEST_URI} ^/rml/cc
RewriteRule ^rml/cc/?$ https://kg-construct.github.io/rml-cc/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/cc/spec
RewriteRule ^rml/cc/spec/?$ https://kg-construct.github.io/rml-cc/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/cc/shapes
RewriteRule ^rml/cc/shapes/?$ https://kg-construct.github.io/rml-cc/shapes/cc.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/(gatherAs|allowEmptyListAndContainer|gather|GatherMap|append|cartessianProduct)$
RewriteRule ^rml/(.*)$ /rml/$1.cc.conneg [NE,R,L]
RewriteCond %{REQUEST_URI} cc
RewriteRule cc/?$ https://kg-construct.github.io/rml-cc/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} cc/spec
RewriteRule cc/spec/?$ https://kg-construct.github.io/rml-cc/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} cc/shapes
RewriteRule cc/shapes/?$ https://kg-construct.github.io/rml-cc/shapes/cc.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} (gatherAs|allowEmptyListAndContainer|gather|GatherMap|append|cartessianProduct)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1.cc.conneg [NE,R,L]


# === RML core ===
RewriteCond %{REQUEST_URI} ^/rml/core
RewriteRule ^rml/core/?$ https://kg-construct.github.io/rml-core/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/core/spec
RewriteRule ^rml/core/spec/?$ https://kg-construct.github.io/rml-core/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/core/shapes
RewriteRule ^rml/core/shapes/?$ https://kg-construct.github.io/rml-core/shapes/core.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/core/bc
RewriteRule ^rml/core/bc/?$ https://kg-construct.github.io/rml-core/ontology/rml-core-bc.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/(logicalSource|logicalTarget|subject|subjectMap|predicateObjectMap|graph|graphMap|class|predicate|predicateMap|object|objectMap|parentTriplesMap|joinCondition|parentMap|parent|childMap|child|datatype|datatypeMap|language|languageMap|termType|template|reference|constant|strategy|TriplesMap|SubjectMap|PredicateObjectMap|PredicateMap|ObjectMap|RefObjectMap|Join|LanguageMap|GraphMap|Strategy|DatatypeMap|ParentMap|ChildMap|TermMap|ExpressionMap|IRI|Literal|BlankNode)$
RewriteRule ^rml/(.*)$ /rml/$1.core.conneg [NE,R,L]
RewriteCond %{REQUEST_URI} core
RewriteRule core/?$ https://kg-construct.github.io/rml-core/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} core/spec
RewriteRule core/spec/?$ https://kg-construct.github.io/rml-core/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} core/shapes
RewriteRule core/shapes/?$ https://kg-construct.github.io/rml-core/shapes/core.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} core/bc
RewriteRule core/bc/?$ https://kg-construct.github.io/rml-core/ontology/rml-core-bc.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} (logicalSource|logicalTarget|subject|subjectMap|predicateObjectMap|graph|graphMap|class|predicate|predicateMap|object|objectMap|parentTriplesMap|joinCondition|parentMap|parent|childMap|child|datatype|datatypeMap|language|languageMap|termType|template|reference|constant|strategy|TriplesMap|SubjectMap|PredicateObjectMap|PredicateMap|ObjectMap|RefObjectMap|Join|LanguageMap|GraphMap|Strategy|DatatypeMap|ParentMap|ChildMap|TermMap|ExpressionMap|IRI|Literal|BlankNode)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1.core.conneg [NE,R,L]


# === RML eval17 ===
RewriteRule ^editor/eval17/?$ https://w3id.org/rml/editor/eval17 [NE,L,R=301]
RewriteRule editor/eval17/?$ https://w3id.org/rml/editor/eval17 [NE,L,R=301]


# === RML fnml ===
RewriteCond %{REQUEST_URI} ^/rml/fnml
RewriteRule ^rml/fnml/?$ https://kg-construct.github.io/rml-fnml/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/fnml/spec
RewriteRule ^rml/fnml/spec/?$ https://kg-construct.github.io/rml-fnml/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/fnml/shapes
RewriteRule ^rml/fnml/shapes/?$ https://kg-construct.github.io/rml-fnml/shapes/fnml.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/(returnMap|functionExecution|input|functionMap|parameterMap|function|parameter|return|inputValueMap|inputValue|ReturnMap|FunctionExecution|Input|ParameterMap|FunctionMap)$
RewriteRule ^rml/(.*)$ /rml/$1.fnml.conneg [NE,R,L]
RewriteCond %{REQUEST_URI} fnml
RewriteRule fnml/?$ https://kg-construct.github.io/rml-fnml/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} fnml/spec
RewriteRule fnml/spec/?$ https://kg-construct.github.io/rml-fnml/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} fnml/shapes
RewriteRule fnml/shapes/?$ https://kg-construct.github.io/rml-fnml/shapes/fnml.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} (returnMap|functionExecution|input|functionMap|parameterMap|function|parameter|return|inputValueMap|inputValue|ReturnMap|FunctionExecution|Input|ParameterMap|FunctionMap)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1.fnml.conneg [NE,R,L]


# === RML io ===
RewriteCond %{REQUEST_URI} ^/rml/io
RewriteRule ^rml/io/?$ https://kg-construct.github.io/rml-io/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/io/spec
RewriteRule ^rml/io/spec/?$ https://kg-construct.github.io/rml-io/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/io/shapes
RewriteRule ^rml/io/shapes/?$ https://kg-construct.github.io/rml-io/shapes/io.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/io/bc
RewriteRule ^rml/io/bc/?$ https://kg-construct.github.io/rml-io/ontology/rml-io-bc.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/(source|target|encoding|compression|serialization|null|referenceFormulation|iterator|namespacePrefix|namespaceURL|namespace|LogicalSource|LogicalTarget|ReferenceFormulation|Source|Target|Namespace|Encoding|Compression|JSONPath|XPath|XPathReferenceFormulation|CSV|SQL2008Table|SQL2008Query|UTF-8|UTF-16|none|gzip|zip|tarxz|targzip)$
RewriteRule ^rml/(.*)$ /rml/$1.io.conneg [NE,R,L]
RewriteCond %{REQUEST_URI} io
RewriteRule io/?$ https://kg-construct.github.io/rml-io/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} io/spec
RewriteRule io/spec/?$ https://kg-construct.github.io/rml-io/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} io/shapes
RewriteRule io/shapes/?$ https://kg-construct.github.io/rml-io/shapes/io.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} io/bc
RewriteRule io/bc/?$ https://kg-construct.github.io/rml-io/ontology/rml-io-bc.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} (source|target|encoding|compression|serialization|null|referenceFormulation|iterator|namespacePrefix|namespaceURL|namespace|LogicalSource|LogicalTarget|ReferenceFormulation|Source|Target|Namespace|Encoding|Compression|JSONPath|XPath|XPathReferenceFormulation|CSV|SQL2008Table|SQL2008Query|UTF-8|UTF-16|none|gzip|zip|tarxz|targzip)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1.io.conneg [NE,R,L]


# === RML resources ===
RewriteRule ^rml//?$ https://kg-construct.github.io/rml-resources/ontology.ttl [NE,L,R=301]
RewriteRule ^$ https://%{SERVER_NAME}/ontology.resource.conneg [NE,R,L]

RewriteRule ^rml/bc/?$ https://kg-construct.github.io/rml-resources/backwards-compatibility.ttl [NE,L,R=301]
RewriteCond %{REQUEST_URI} bc$
RewriteRule (.*)$ https://%{SERVER_NAME}/backwards-compatibility.resource.conneg [NE,R,L]

RewriteRule ^rml/portal/?(.*)/?$ https://kg-construct.github.io/rml-resources/portal/$1 [NE,L,R=301]
RewriteRule portal/?(.*)/?$ https://kg-construct.github.io/rml-resources/portal/$1 [NE,L,R=301]

RewriteRule ^rml/shapes/?$ https://kg-construct.github.io/rml-resources/shapes.ttl [NE,L,R=301]
RewriteCond %{REQUEST_URI} shapes$
RewriteRule (.*)$ https://%{SERVER_NAME}/shapes.resource.conneg [NE,R,L]

RewriteRule ^rml/resources/?(.*)/?$ https://kg-construct.github.io/rml-resources/resources/$1 [NE,L,R=301]
RewriteRule resources/?(.*)/?$ https://kg-construct.github.io/rml-resources/resources/$1 [NE,L,R=301]


# === RML star ===
RewriteCond %{REQUEST_URI} ^/rml/star
RewriteRule ^rml/star/?$ https://kg-construct.github.io/rml-star/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/star/spec
RewriteRule ^rml/star/spec/?$ https://kg-construct.github.io/rml-star/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/star/shapes
RewriteRule ^rml/star/shapes/?$ https://kg-construct.github.io/rml-star/shapes/star.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} ^/rml/(quotedTriplesMap|StarMap|AssertedTriplesMap|NonAssertedTriplesMap)$
RewriteRule ^rml/(.*)$ /rml/$1.star.conneg [NE,R,L]
RewriteCond %{REQUEST_URI} star
RewriteRule star/?$ https://kg-construct.github.io/rml-star/ontology/documentation/index-en.html [NE,R,L]
RewriteCond %{REQUEST_URI} star/spec
RewriteRule star/spec/?$ https://kg-construct.github.io/rml-star/spec/docs [NE,R,L]
RewriteCond %{REQUEST_URI} star/shapes
RewriteRule star/shapes/?$ https://kg-construct.github.io/rml-star/shapes/star.ttl [NE,R,L]
RewriteCond %{REQUEST_URI} (quotedTriplesMap|StarMap|AssertedTriplesMap|NonAssertedTriplesMap)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1.star.conneg [NE,R,L]


RewriteRule ^rml/(.*)$ https://kg-construct.github.io/rml-resources/404.html [NE,L,R=404]
RewriteRule ^(.*)$ https://kg-construct.github.io/rml-resources/404.html [NE,L,R=404]

0 comments on commit 8880dd7

Please sign in to comment.