Skip to content

Commit

Permalink
Add citation generation and pushed python to 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
enridaga committed Jan 17, 2024
1 parent 86800d5 commit 02b40c7
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/reeco_initialize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ jobs:
pip install pysparql-anything
python build_rdf_data_files.py
- name: build Citation data CSV
id: build_citation_data_file
run: |
pip install pysparql-anything
python build_citation_data_file.py
- name: get current date
id: date
run: echo "::set-output name=date::$(date +'%Y_%m_%d_%H-%M')"
Expand Down
40 changes: 40 additions & 0 deletions build_citation_data_file.py
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)

54 changes: 54 additions & 0 deletions component-citation.sparql
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

}
}
}
}

2 changes: 1 addition & 1 deletion components-to-rdf.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ WHERE {

#--> Step 3. parse the YAML content
fx:properties fx:content ?content ;
fx:triplifier "com.github.sparqlanything.yaml.YAMLTriplifier" ; fx:blank-nodes "false".
fx:triplifier "io.github.sparqlanything.yaml.YAMLTriplifier" ; fx:blank-nodes "false".

#--> Step 4. Query the Ecosystem Schema annotations (when the schema evolves, change only this!)
{ # Components:
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ Deprecated==1.2.14
idna==2.10
isodate==0.6.1
pycparser==2.21
PyGithub==1.59.1
pyjnius==1.5.0
PyGithub==1.58.1
pyjnius==1.6.0
PyJWT==2.8.0
PyNaCl==1.5.0
pyparsing==3.1.1
pysparql_anything==0.9.0.1
python-frontmatter==1.0.0
PyYAML==6.0.1
rdflib==7.0.0
rdflib==6.3.1
reeco==0.0.2.post1697540418
requests==2.25.1
requests>=2.25.1
schema==0.7.5
six==1.16.0
tqdm==4.66.1
tqdm==4.65.0
urllib3==1.26.16
wrapt==1.15.0

0 comments on commit 02b40c7

Please sign in to comment.