Skip to content
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

Make basicdoc the default text model for textual content in Relaton #89

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ RelatonBib::BibXMLParser.parse bibxml

[source,ruby]
----
item.to_hash
item.to_h
=> {"schema-version"=>"v1.2.1",
"id"=>"ISOTC211",
"title"=>
Expand Down
5 changes: 4 additions & 1 deletion grammars/basicdoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@
<data type="ID"/>
</attribute>
<attribute name="reviewer"/>
<optional>
<attribute name="type"/>
</optional>
<optional>
<attribute name="date">
<data type="dateTime"/>
Expand Down Expand Up @@ -986,7 +989,7 @@
This is xref with fixed @type="footnote", and @target built in as paragraph+
@reference replaces ReferenceElement/text
so <fn reference="2"><p>This is a footnote</p></fn>
corresponds to
corresponds to
<eref type="footnote" target="fn2">2</xref> <p id="fn2">This is a footnote</p>
-->
<define name="callout">
Expand Down
124 changes: 71 additions & 53 deletions grammars/biblio.rng
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<text/>
</element>
</define>
<define name="LocalizedString1">
<define name="LocalizedStringAttrs">
<optional>
<!-- multiple languages and scripts possible: comma delimit them if so -->
<attribute name="language"/>
Expand All @@ -106,6 +106,10 @@
<optional>
<attribute name="script"/>
</optional>
</define>
<define name="LocalizedString1">
<!-- multiple languages and scripts possible: comma delimit them if so -->
<ref name="LocalizedStringAttrs"/>
<text/>
</define>
<define name="LocalizedString">
Expand Down Expand Up @@ -142,16 +146,8 @@
<ref name="LocalizedStringOrXsAny"/>
</define>
<define name="LocalizedStringOrXsAny1">
<optional>
<!-- multiple languages and scripts possible: comma delimit them if so -->
<attribute name="language"/>
</optional>
<optional>
<attribute name="locale"/>
</optional>
<optional>
<attribute name="script"/>
</optional>
<!-- multiple languages and scripts possible: comma delimit them if so -->
<ref name="LocalizedStringAttrs"/>
<oneOrMore>
<choice>
<text/>
Expand Down Expand Up @@ -208,7 +204,10 @@
</define>
<define name="roledescription">
<element name="description">
<ref name="FormattedString"/>
<ref name="LocalizedStringAttrs"/>
<oneOrMore>
<ref name="TextElement"/>
</oneOrMore>
</element>
</define>
<define name="person">
Expand Down Expand Up @@ -333,34 +332,40 @@
</define>
<define name="affiliationdescription">
<element name="description">
<ref name="FormattedString"/>
<ref name="LocalizedStringAttrs"/>
<oneOrMore>
<ref name="TextElement"/>
</oneOrMore>
</element>
</define>
<define name="organization">
<element name="organization">
<oneOrMore>
<ref name="orgname"/>
</oneOrMore>
<zeroOrMore>
<ref name="subdivision"/>
</zeroOrMore>
<optional>
<ref name="abbreviation"/>
</optional>
<zeroOrMore>
<ref name="uri"/>
</zeroOrMore>
<zeroOrMore>
<ref name="org-identifier"/>
</zeroOrMore>
<zeroOrMore>
<ref name="contact"/>
</zeroOrMore>
<optional>
<ref name="logo"/>
</optional>
<ref name="OrganizationType"/>
</element>
</define>
<define name="OrganizationType">
<oneOrMore>
<ref name="orgname"/>
</oneOrMore>
<zeroOrMore>
<ref name="subdivision"/>
</zeroOrMore>
<optional>
<ref name="abbreviation"/>
</optional>
<zeroOrMore>
<ref name="uri"/>
</zeroOrMore>
<zeroOrMore>
<ref name="org-identifier"/>
</zeroOrMore>
<zeroOrMore>
<ref name="contact"/>
</zeroOrMore>
<optional>
<ref name="logo"/>
</optional>
</define>
<define name="orgname">
<element name="name">
<choice>
Expand All @@ -371,10 +376,10 @@
</define>
<define name="subdivision">
<element name="subdivision">
<choice>
<ref name="LocalizedString"/>
<ref name="NameWithVariants"/>
</choice>
<optional>
<attribute name="type"/>
</optional>
<ref name="OrganizationType"/>
</element>
</define>
<define name="logo">
Expand Down Expand Up @@ -894,7 +899,9 @@
</define>
<define name="formattedref">
<element name="formattedref">
<ref name="FormattedString"/>
<oneOrMore>
<ref name="TextElement"/>
</oneOrMore>
</element>
</define>
<define name="license">
Expand Down Expand Up @@ -939,7 +946,10 @@
<optional>
<attribute name="type"/>
</optional>
<ref name="FormattedString"/>
<ref name="LocalizedStringAttrs"/>
<zeroOrMore>
<ref name="TextElement"/>
</zeroOrMore>
</define>
<!-- TitleType = ( "alternative" | "original" | "unofficial" | "subtitle" | "main" ) -->
<define name="TypedUri">
Expand Down Expand Up @@ -1030,16 +1040,10 @@
<data type="boolean"/>
</attribute>
</optional>
<optional>
<attribute name="language"/>
</optional>
<optional>
<attribute name="locale"/>
</optional>
<optional>
<attribute name="script"/>
</optional>
<text/>
<ref name="LocalizedStringAttrs"/>
<oneOrMore>
<ref name="TextElement"/>
</oneOrMore>
</element>
</define>
<define name="docnumber">
Expand Down Expand Up @@ -1264,12 +1268,23 @@
<optional>
<attribute name="type"/>
</optional>
<ref name="FormattedString"/>
<ref name="LocalizedStringAttrs"/>
<oneOrMore>
<ref name="TextElement"/>
</oneOrMore>
</element>
</define>
<define name="bibabstract">
<element name="abstract">
<ref name="FormattedString"/>
<ref name="LocalizedStringAttrs"/>
<choice>
<oneOrMore>
<ref name="BasicBlock"/>
</oneOrMore>
<oneOrMore>
<ref name="TextElement"/>
</oneOrMore>
</choice>
</element>
</define>
<define name="copyright">
Expand Down Expand Up @@ -1374,7 +1389,10 @@
</attribute>
<optional>
<element name="description">
<ref name="FormattedString"/>
<ref name="LocalizedStringAttrs"/>
<oneOrMore>
<ref name="TextElement"/>
</oneOrMore>
</element>
</optional>
<element name="bibitem">
Expand Down
14 changes: 7 additions & 7 deletions grammars/versions.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"relaton-models": "v1.2.8",
"basicdoc-models": "v1.1.2",
"relaton-models": "v1.3.0",
"basicdoc-models": "v1.1.3",
"metanorma-requirements-models": "v1.0.1",
"relaton-model-ieee": "v1.0.1",
"relaton-model-iso": "v1.0.0",
"relaton-model-iso": "v1.0.3",
"relaton-model-iec": "v1.0.0",
"relaton-model-bsi": "v1.0.2",
"relaton-model-gb": "v1.0.0",
"relaton-model-mpfa": "v1.0.0",
"relaton-model-bipm": "v1.0.0",
"relaton-model-bipm": "v1.0.1",
"relaton-model-w3c": "v1.0.0",
"relaton-model-3gpp": "v1.0.1",
"relaton-model-csa": "v1.0.0",
"relaton-model-cc": "v1.0.0",
"relaton-model-ietf": "v1.0.1",
"relaton-model-iho": "v1.0.0",
"relaton-model-itu": "v1.0.0",
"relaton-model-itu": "v1.0.2",
"relaton-model-m3aawg": "v1.0.0",
"relaton-model-nist": "v1.0.0",
"relaton-model-ribose": "v1.0.0",
Expand All @@ -29,6 +29,6 @@
"relaton-model-oasis": "v1.0.1",
"relaton-model-jis": "v0.0.1",
"relaton-model-etsi": "v0.0.3",
"metanorma-model": "v1.2.11",
"date": "2024-01-04T03:55:06Z"
"metanorma-model": "v1.3.1",
"date": "2024-04-07T02:56:44Z"
}
38 changes: 22 additions & 16 deletions lib/relaton_bib.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
require "uri"
require "nokogiri"
require "forwardable"
require "yaml"
require "htmlentities"
require "relaton_bib/version"
require "relaton_bib/deep_dup"
require "relaton_bib/config"
require "relaton_bib/util"
require "relaton_bib/localized_string"
require "relaton_bib/forename"
require "relaton_bib/full_name"
require "relaton_bib/contributor"
require "relaton_bib/document_type"
require "relaton_bib/image"
require "relaton_bib/factory"
require "relaton_bib/parser/xml/locality"
require "relaton_bib/parser/xml"
require "relaton_bib/typed_uri"
require "relaton_bib/element/parser"
require "relaton_bib/bibliographic_item"
require "relaton_bib/hit_collection"
require "relaton_bib/contributor"
require "relaton_bib/abstract"
require "relaton_bib/affiliation"
require "relaton_bib/hit"
require "relaton_bib/bibxml_parser"
require "relaton_bib/renderer/bibtex_builder"
require "relaton_bib/renderer/bibxml"

Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"
module RelatonBib
class Error < StandardError; end

Expand Down Expand Up @@ -94,15 +100,15 @@ def self.grammar_hash
Digest::MD5.hexdigest RelatonBib::VERSION # grammars
end

private
# private

# @param array [Array]
# @return [Array<String>, String]
def single_element_array(array)
# if array.size > 1
array.map { |e| e.is_a?(String) ? e : e.to_hash }
# else
# array.first.is_a?(String) ? array[0] : array.first&.to_hash
# end
end
# # @param array [Array]
# # @return [Array<String>, String]
# def single_element_array(array)
# # if array.size > 1
# array.map { |e| e.is_a?(String) ? e : e.to_h }
# # else
# # array.first.is_a?(String) ? array[0] : array.first&.to_h
# # end
# end
end
39 changes: 39 additions & 0 deletions lib/relaton_bib/abstract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module RelatonBib
class Abstract
include LocalizedStringAttrs
include RelatonBib::Element::Base

# @!attribute [r] content BasicBlock, TextElement
# @return [Array<RelatonBib::Element::Base>]

#
# Initialize abstract
# language and script can be multiple: comma delimit them if so
#
# @param [Array<RelatonBib::Element::Base>, Strign] content abstract content
# @param [Array<String>, String] :language language code Iso639
# @param [Array<Atring>, String] :script script code Iso15924
# @param [String, nil] :locale
#
def initialize(content:, **args)
super
if content.is_a?(String)
@content = Element.parse_basic_block_elements(content)
@content = Element.parse_text_elements(content) if @content.empty?
else
@content = content
end
end

def to_xml(builder)
builder.abstract { |b| super b }
end

def to_asciibib(prefix = "", count = 1)
pref = prefix.empty? ? "abstract" : "#{prefix}.abstract"
out = count > 1 ? "#{pref}::\n" : ""
out += super(pref)
out
end
end
end
Loading
Loading