forked from polifonia-project/ecosystem
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add citation generation and pushed python to 3.9
- Loading branch information
Showing
5 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pysparql_anything as pysa | ||
import os | ||
import yaml | ||
|
||
config = yaml.load(open('_config.yml','r'), Loader=yaml.Loader) | ||
namespace = config['rdf']['namespace'] | ||
engine = pysa.SparqlAnything() | ||
directory = './content/' | ||
includes = './_includes/cite/' | ||
for root, dirs, files in os.walk(directory): | ||
for filename in files: | ||
if not filename.endswith('.md'): | ||
continue | ||
location = os.path.join(root, filename) | ||
if "/.github/" in location: | ||
continue | ||
#print(location) | ||
pre, ext = os.path.splitext(location) | ||
output_includes = pre.replace("./content/", includes) | ||
output_includes_apa = output_includes + ".cite.apa" | ||
output_includes_bib = output_includes + ".cite.bib" | ||
#pth = os.path.dirname(os.path.abspath(output)) | ||
pth_includes = os.path.dirname(os.path.abspath(output_includes)) | ||
#if not os.path.exists(pth): | ||
# os.makedirs(pth) | ||
if not os.path.exists(pth_includes): | ||
os.makedirs(pth_includes) | ||
d = engine.select(q='./component-citation.sparql', v={'componentFile': location}) # | ||
if len(d['results']['bindings']) == 0 or 'component' not in d['results']['bindings'][0]: | ||
continue | ||
if 'apa' in d['results']['bindings'][0]: | ||
apa = d['results']['bindings'][0]['apa']['value'] | ||
f1 = open(output_includes_apa, 'w') | ||
f1.write(apa) | ||
|
||
if 'bibtex' in d['results']['bindings'][0]: | ||
bibtex = d['results']['bindings'][0]['bibtex']['value'] | ||
f1 = open(output_includes_bib, 'w') | ||
f1.write(bibtex) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | ||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | ||
PREFIX fx: <http://sparql.xyz/facade-x/ns/> | ||
PREFIX xyz: <http://sparql.xyz/facade-x/data/> | ||
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> | ||
PREFIX schema: <https://schema.org/> | ||
PREFIX fabio: <http://purl.org/spar/fabio/> | ||
PREFIX frapo: <http://purl.org/cerif/frapo/> | ||
|
||
SELECT ?component ?doi ?apa ?bibtex | ||
WHERE { | ||
SERVICE <x-sparql-anything:> { | ||
|
||
SERVICE <x-sparql-anything:> { | ||
|
||
SERVICE <x-sparql-anything:> { | ||
|
||
# --> Step 2. extract the YAML fontmatter from files with component annotations | ||
fx:properties fx:location ?_componentFile . | ||
[] a xyz:YamlFrontMatter ; fx:anySlot ?yaml | ||
} | ||
|
||
BIND ( ?yaml as ?content ) . | ||
|
||
#--> Step 3. parse the YAML content | ||
fx:properties fx:content ?content ; | ||
fx:triplifier "io.github.sparqlanything.yaml.YAMLTriplifier" ; fx:blank-nodes "false" ; fx:yaml.allow-duplicate-keys true. | ||
|
||
{ # Components: | ||
# Id | ||
?x xyz:component-id ?component . | ||
?x xyz:doi ?doi . | ||
} | ||
} | ||
### curl -LH "Accept: text/x-bibliography; style=apa" https://doi.org/10.1126/science.169.3946.635 | ||
|
||
BIND ( CONCAT("https://doi.org/", ?doi) as ?doiLink ) . | ||
fx:properties fx:location ?doiLink ; | ||
fx:http.header.accept "text/x-bibliography; style=apa" ; | ||
fx:media-type "text/plain" . | ||
[] rdf:_1 ?apa | ||
|
||
OPTIONAL{ | ||
SERVICE <x-sparql-anything:> { | ||
fx:properties fx:location ?doiLink ; | ||
fx:http.header.accept "text/x-bibliography; style=bibtex" ; | ||
fx:media-type "text/plain" . | ||
[] rdf:_1 ?bibtex | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters