-
-
Notifications
You must be signed in to change notification settings - Fork 20
Hacks to demo possible CiTO support #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
egonw
wants to merge
3
commits into
openjournals:main
Choose a base branch
from
egonw:enhancement/cito2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,246 @@ | ||
-- Copyright © 2017–2021 Albert Krewinkel, Robert Winkler | ||
-- | ||
-- This library is free software; you can redistribute it and/or modify it | ||
-- under the terms of the MIT license. See LICENSE for details. | ||
|
||
local _version = '1.0.0' | ||
local properties_and_aliases = { | ||
agreesWith = { | ||
'agreeWith', | ||
'agree_with', | ||
'agrees_with', | ||
}, | ||
citation = { | ||
}, | ||
cites = { | ||
}, | ||
citesAsAuthority = { | ||
'asAuthority', | ||
'cites_as_authority', | ||
'as_authority', | ||
'authority' | ||
}, | ||
citesAsDataSource = { | ||
"asDataSource", | ||
"dataSource", | ||
'cites_as_data_source', | ||
"as_data_source", | ||
"data_source" | ||
}, | ||
citesAsEvidence = { | ||
'asEvidence', | ||
'cites_as_evidence', | ||
'as_evidence', | ||
'evidence' | ||
}, | ||
citesAsMetadataDocument = { | ||
'asMetadataDocument', | ||
'metadataDocument', | ||
'cites_as_metadata_document', | ||
'as_metadata_document', | ||
'metadata_document', | ||
'metadata' | ||
}, | ||
citesAsPotentialSolution = { | ||
'cites_as_potential_solution', | ||
'potentialSolution', | ||
'potential_solution', | ||
'solution' | ||
}, | ||
citesAsRecommendedReading = { | ||
'asRecommendedReading', | ||
'recommendedReading', | ||
'cites_as_recommended_reading', | ||
'as_recommended_reading', | ||
'recommended_reading' | ||
}, | ||
citesAsRelated = { | ||
'cites_as_related', | ||
'related', | ||
}, | ||
citesAsSourceDocument = { | ||
'cites_as_source_document', | ||
'sourceDocument', | ||
'source_document' | ||
}, | ||
citesForInformation = { | ||
'cites_for_information', | ||
'information', | ||
}, | ||
compiles = { | ||
}, | ||
confirms = { | ||
}, | ||
containsAssertionFrom = { | ||
}, | ||
corrects = { | ||
}, | ||
credits = { | ||
}, | ||
critiques = { | ||
}, | ||
derides = { | ||
}, | ||
describes = { | ||
}, | ||
disagreesWith = { | ||
'disagrees_with', | ||
'disagree', | ||
'disagrees' | ||
}, | ||
discusses = { | ||
}, | ||
disputes = { | ||
}, | ||
documents = { | ||
}, | ||
extends = { | ||
}, | ||
includesExcerptFrom = { | ||
'excerptFrom', | ||
'excerpt', | ||
'excerpt_from', | ||
'includes_excerpt_from', | ||
}, | ||
includesQuotationFrom = { | ||
'quotationFrom', | ||
'includes_quotation_from', | ||
'quotation', | ||
'quotation_from' | ||
}, | ||
linksTo = { | ||
'links_to', | ||
'link' | ||
}, | ||
obtainsBackgroundFrom = { | ||
'backgroundFrom', | ||
'obtains_background_from', | ||
'background', | ||
'background_from' | ||
}, | ||
providesDataFor = { | ||
}, | ||
obtainsSupportFrom = { | ||
}, | ||
qualifies = { | ||
}, | ||
parodies = { | ||
}, | ||
refutes = { | ||
}, | ||
repliesTo = { | ||
'replies_to', | ||
}, | ||
retracts = { | ||
}, | ||
reviews = { | ||
}, | ||
ridicules = { | ||
}, | ||
speculatesOn = { | ||
}, | ||
supports = { | ||
}, | ||
updates = { | ||
}, | ||
usesConclusionsFrom = { | ||
'uses_conclusions_from' | ||
}, | ||
usesDataFrom = { | ||
'dataFrom', | ||
'uses_data_from', | ||
'data', | ||
'data_from' | ||
}, | ||
usesMethodIn = { | ||
'methodIn', | ||
'uses_method_in', | ||
'method', | ||
'method_in' | ||
}, | ||
} | ||
|
||
local default_cito_property = 'citation' | ||
|
||
--- Map from cito aliases to the actual cito property. | ||
local properties_by_alias = {} | ||
for property, aliases in pairs(properties_and_aliases) do | ||
-- every property is an alias for itself | ||
properties_by_alias[property] = property | ||
for _, alias in pairs(aliases) do | ||
properties_by_alias[alias] = property | ||
end | ||
end | ||
|
||
--- Split citation ID into cito property and the actual citation ID. If | ||
--- the ID does not seem to contain a CiTO property, the | ||
--- `default_cito_property` will be returned, together with the | ||
--- unchanged input ID. | ||
local function split_cito_from_id (citation_id) | ||
local split_citation_id = {} | ||
local cito_props = {} | ||
local id_started = false | ||
|
||
for part in citation_id:gmatch('[^:]+') do | ||
if not id_started and properties_by_alias[part] then | ||
table.insert(cito_props, properties_by_alias[part]) | ||
else | ||
id_started = true | ||
end | ||
|
||
if id_started then | ||
table.insert(split_citation_id, 1, part) | ||
end | ||
end | ||
|
||
if next(split_citation_id) == nill then | ||
table.insert(split_citation_id, table.remove(cito_props)) | ||
end | ||
|
||
return cito_props, table.concat(split_citation_id, ':') | ||
end | ||
|
||
--- CiTO properties by citation. | ||
local function store_cito (cito_cites, prop, cite_id) | ||
if not prop then | ||
return | ||
end | ||
if not cito_cites[cite_id] then | ||
cito_cites[cite_id] = {} | ||
end | ||
table.insert(cito_cites[cite_id], prop) | ||
end | ||
|
||
|
||
--- Returns a Cite filter function which extracts CiTO information and | ||
--- add it to the given collection table. | ||
local function extract_cito (cito_cites) | ||
return function (cite) | ||
for k, citation in pairs(cite.citations) do | ||
local cito_props, cite_id = split_cito_from_id(citation.id) | ||
for l, cito_prop in pairs(cito_props) do | ||
store_cito(cito_cites, cito_prop, cite_id) | ||
end | ||
citation.id = cite_id | ||
end | ||
return cite | ||
end | ||
end | ||
|
||
--- Lists of citation IDs, indexed by CiTO properties. | ||
local properties_by_citation = {} | ||
|
||
return { | ||
{ | ||
Cite = extract_cito(properties_by_citation) | ||
}, | ||
{ | ||
Meta = function (meta) | ||
meta.citation_properties = properties_by_citation | ||
meta.bibliography = meta.bibliography or | ||
meta.cito_bibliography or | ||
meta['cito-bibliography'] | ||
return meta | ||
end | ||
} | ||
} |
This file contains hidden or 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,55 @@ | ||
-- Copyright © 2021 Albert Krewinkel | ||
-- | ||
-- This library is free software; you can redistribute it and/or modify it | ||
-- under the terms of the MIT license. See LICENSE for details. | ||
|
||
local List = require 'pandoc.List' | ||
local utils = require 'pandoc.utils' | ||
local citation_properties | ||
|
||
local function meta_citation_properties (meta) | ||
citation_properties = meta.citation_properties | ||
end | ||
|
||
local function cito_properties(cite_id) | ||
local props = citation_properties[cite_id] | ||
if not props then return {} end | ||
|
||
-- remove duplicates | ||
local deduplicated_props = List() | ||
local seen = {} | ||
for _, prop in ipairs(props) do | ||
if not seen[prop] then | ||
deduplicated_props:insert(prop) | ||
seen[prop] = true | ||
end | ||
end | ||
|
||
return List(deduplicated_props):map( | ||
function (x) | ||
return pandoc.Strong{ | ||
pandoc.Space(), | ||
pandoc.Str '[cito:', | ||
pandoc.Str(utils.stringify(x)), | ||
pandoc.Str ']' | ||
} | ||
end | ||
) | ||
end | ||
|
||
local function add_cito (div) | ||
local cite_id = div.identifier:match 'ref%-(.*)' | ||
if cite_id and div.classes:includes 'csl-entry' then | ||
for k, v in ipairs( div.content ) do | ||
if k == 1 then | ||
v.content:extend(cito_properties(cite_id)) | ||
return div | ||
end | ||
end | ||
end | ||
end | ||
|
||
return { | ||
{Meta = meta_citation_properties}, | ||
{Div = add_cito}, | ||
} |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not also put this in the
pdf.yaml
configuration?