Skip to content

Commit

Permalink
feat(Math): Add Math, MathFragment and MathBlock nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jan 20, 2020
1 parent 1a16a1f commit 74f4b55
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 6 deletions.
75 changes: 72 additions & 3 deletions py/stencila/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,69 @@ def __init__(
self.checked = checked


class Math(Entity):
"""A mathematical variable or equation."""

text: str
mathLanguage: Optional[str] = None

def __init__(
self,
text: str,
id: Optional[str] = None,
mathLanguage: Optional[str] = None,
meta: Optional[Dict[str, Any]] = None
) -> None:
super().__init__(
id=id,
meta=meta
)
if text is not None:
self.text = text
if mathLanguage is not None:
self.mathLanguage = mathLanguage


class MathBlock(Math):
"""A block of math, e.g an equation, to be treated as block content."""

def __init__(
self,
text: str,
id: Optional[str] = None,
mathLanguage: Optional[str] = None,
meta: Optional[Dict[str, Any]] = None
) -> None:
super().__init__(
text=text,
id=id,
mathLanguage=mathLanguage,
meta=meta
)



class MathFragment(Math):
"""
A fragment of math, e.g a variable name, to be treated as inline content.
"""

def __init__(
self,
text: str,
id: Optional[str] = None,
mathLanguage: Optional[str] = None,
meta: Optional[Dict[str, Any]] = None
) -> None:
super().__init__(
text=text,
id=id,
mathLanguage=mathLanguage,
meta=meta
)



class Organization(Thing):
"""An organization such as a school, NGO, corporation, club, etc."""

Expand Down Expand Up @@ -2493,7 +2556,7 @@ def __init__(
"""
Union type for valid block content.
"""
BlockContent = Union["CodeBlock", "CodeChunk", "Heading", "List", "ListItem", "Paragraph", "QuoteBlock", "Table", "ThematicBreak"]
BlockContent = Union["CodeBlock", "CodeChunk", "Heading", "List", "ListItem", "MathBlock", "Paragraph", "QuoteBlock", "Table", "ThematicBreak"]


"""
Expand Down Expand Up @@ -2523,13 +2586,13 @@ def __init__(
"""
All type schemas that are derived from Entity
"""
EntityTypes = Union["Entity", "ArraySchema", "Article", "AudioObject", "BooleanSchema", "Brand", "Cite", "CiteGroup", "Code", "CodeBlock", "CodeChunk", "CodeError", "CodeExpression", "CodeFragment", "Collection", "ConstantSchema", "ContactPoint", "CreativeWork", "Datatable", "DatatableColumn", "Date", "Delete", "Emphasis", "EnumSchema", "Figure", "Function", "Heading", "ImageObject", "Include", "IntegerSchema", "Link", "List", "ListItem", "Mark", "MediaObject", "NumberSchema", "Organization", "Paragraph", "Parameter", "Periodical", "Person", "Product", "PublicationIssue", "PublicationVolume", "Quote", "QuoteBlock", "SoftwareApplication", "SoftwareEnvironment", "SoftwareSession", "SoftwareSourceCode", "StringSchema", "Strong", "Subscript", "Superscript", "Table", "TableCell", "TableRow", "ThematicBreak", "Thing", "TupleSchema", "Variable", "VideoObject", "VolumeMount"]
EntityTypes = Union["Entity", "ArraySchema", "Article", "AudioObject", "BooleanSchema", "Brand", "Cite", "CiteGroup", "Code", "CodeBlock", "CodeChunk", "CodeError", "CodeExpression", "CodeFragment", "Collection", "ConstantSchema", "ContactPoint", "CreativeWork", "Datatable", "DatatableColumn", "Date", "Delete", "Emphasis", "EnumSchema", "Figure", "Function", "Heading", "ImageObject", "Include", "IntegerSchema", "Link", "List", "ListItem", "Mark", "Math", "MathBlock", "MathFragment", "MediaObject", "NumberSchema", "Organization", "Paragraph", "Parameter", "Periodical", "Person", "Product", "PublicationIssue", "PublicationVolume", "Quote", "QuoteBlock", "SoftwareApplication", "SoftwareEnvironment", "SoftwareSession", "SoftwareSourceCode", "StringSchema", "Strong", "Subscript", "Superscript", "Table", "TableCell", "TableRow", "ThematicBreak", "Thing", "TupleSchema", "Variable", "VideoObject", "VolumeMount"]


"""
Union type for valid inline content.
"""
InlineContent = Union[None, bool, int, float, str, "CodeFragment", "CodeExpression", "Delete", "Emphasis", "ImageObject", "Link", "Quote", "Strong", "Subscript", "Superscript", "Cite", "CiteGroup"]
InlineContent = Union[None, bool, int, float, str, "CodeFragment", "CodeExpression", "Delete", "Emphasis", "ImageObject", "Link", "MathFragment", "Quote", "Strong", "Subscript", "Superscript", "Cite", "CiteGroup"]


"""
Expand All @@ -2538,6 +2601,12 @@ def __init__(
MarkTypes = Union["Mark", "Delete", "Emphasis", "Quote", "Strong", "Subscript", "Superscript"]


"""
All type schemas that are derived from Math
"""
MathTypes = Union["Math", "MathBlock", "MathFragment"]


"""
All type schemas that are derived from MediaObject
"""
Expand Down
95 changes: 92 additions & 3 deletions r/R/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,89 @@ ListItem <- function(
}


#' A mathematical variable or equation.
#'
#' @name Math
#' @param text The text of the equation in the language. \bold{Required}.
#' @param id The identifier for this item.
#' @param mathLanguage The language used for the equation e.g tex, mathml, asciimath.
#' @param meta Metadata associated with this item.
#' @seealso \code{\link{Entity}}
#' @export
Math <- function(
text,
id,
mathLanguage,
meta
){
self <- Entity(
id = id,
meta = meta
)
self$type <- as_scalar("Math")
self[["text"]] <- check_property("Math", "text", TRUE, missing(text), "character", text)
self[["mathLanguage"]] <- check_property("Math", "mathLanguage", FALSE, missing(mathLanguage), "character", mathLanguage)
class(self) <- c(class(self), "Math")
self
}


#' A block of math, e.g an equation, to be treated as block content.
#'
#' @name MathBlock
#' @param text The text of the equation in the language. \bold{Required}.
#' @param id The identifier for this item.
#' @param mathLanguage The language used for the equation e.g tex, mathml, asciimath.
#' @param meta Metadata associated with this item.
#' @seealso \code{\link{Math}}
#' @export
MathBlock <- function(
text,
id,
mathLanguage,
meta
){
self <- Math(
text = text,
id = id,
mathLanguage = mathLanguage,
meta = meta
)
self$type <- as_scalar("MathBlock")

class(self) <- c(class(self), "MathBlock")
self
}


#' A fragment of math, e.g a variable name, to be treated as inline content.
#'
#' @name MathFragment
#' @param text The text of the equation in the language. \bold{Required}.
#' @param id The identifier for this item.
#' @param mathLanguage The language used for the equation e.g tex, mathml, asciimath.
#' @param meta Metadata associated with this item.
#' @seealso \code{\link{Math}}
#' @export
MathFragment <- function(
text,
id,
mathLanguage,
meta
){
self <- Math(
text = text,
id = id,
mathLanguage = mathLanguage,
meta = meta
)
self$type <- as_scalar("MathFragment")

class(self) <- c(class(self), "MathFragment")
self
}


#' An organization such as a school, NGO, corporation, club, etc.
#'
#' @name Organization
Expand Down Expand Up @@ -2978,7 +3061,7 @@ VolumeMount <- function(
#' Union type for valid block content.
#'
#' @export
BlockContent <- Union(CodeBlock, CodeChunk, Heading, List, ListItem, Paragraph, QuoteBlock, Table, ThematicBreak)
BlockContent <- Union(CodeBlock, CodeChunk, Heading, List, ListItem, MathBlock, Paragraph, QuoteBlock, Table, ThematicBreak)


#' All type schemas that are derived from CodeBlock
Expand Down Expand Up @@ -3008,13 +3091,13 @@ CreativeWorkTypes <- Union(CreativeWork, Article, AudioObject, Collection, Datat
#' All type schemas that are derived from Entity
#'
#' @export
EntityTypes <- Union(Entity, ArraySchema, Article, AudioObject, BooleanSchema, Brand, Cite, CiteGroup, Code, CodeBlock, CodeChunk, CodeError, CodeExpression, CodeFragment, Collection, ConstantSchema, ContactPoint, CreativeWork, Datatable, DatatableColumn, Date, Delete, Emphasis, EnumSchema, Figure, Function, Heading, ImageObject, Include, IntegerSchema, Link, List, ListItem, Mark, MediaObject, NumberSchema, Organization, Paragraph, Parameter, Periodical, Person, Product, PublicationIssue, PublicationVolume, Quote, QuoteBlock, SoftwareApplication, SoftwareEnvironment, SoftwareSession, SoftwareSourceCode, StringSchema, Strong, Subscript, Superscript, Table, TableCell, TableRow, ThematicBreak, Thing, TupleSchema, Variable, VideoObject, VolumeMount)
EntityTypes <- Union(Entity, ArraySchema, Article, AudioObject, BooleanSchema, Brand, Cite, CiteGroup, Code, CodeBlock, CodeChunk, CodeError, CodeExpression, CodeFragment, Collection, ConstantSchema, ContactPoint, CreativeWork, Datatable, DatatableColumn, Date, Delete, Emphasis, EnumSchema, Figure, Function, Heading, ImageObject, Include, IntegerSchema, Link, List, ListItem, Mark, Math, MathBlock, MathFragment, MediaObject, NumberSchema, Organization, Paragraph, Parameter, Periodical, Person, Product, PublicationIssue, PublicationVolume, Quote, QuoteBlock, SoftwareApplication, SoftwareEnvironment, SoftwareSession, SoftwareSourceCode, StringSchema, Strong, Subscript, Superscript, Table, TableCell, TableRow, ThematicBreak, Thing, TupleSchema, Variable, VideoObject, VolumeMount)


#' Union type for valid inline content.
#'
#' @export
InlineContent <- Union("NULL", "logical", "numeric", "character", CodeFragment, CodeExpression, Delete, Emphasis, ImageObject, Link, Quote, Strong, Subscript, Superscript, Cite, CiteGroup)
InlineContent <- Union("NULL", "logical", "numeric", "character", CodeFragment, CodeExpression, Delete, Emphasis, ImageObject, Link, MathFragment, Quote, Strong, Subscript, Superscript, Cite, CiteGroup)


#' All type schemas that are derived from Mark
Expand All @@ -3023,6 +3106,12 @@ InlineContent <- Union("NULL", "logical", "numeric", "character", CodeFragment,
MarkTypes <- Union(Mark, Delete, Emphasis, Quote, Strong, Subscript, Superscript)


#' All type schemas that are derived from Math
#'
#' @export
MathTypes <- Union(Math, MathBlock, MathFragment)


#' All type schemas that are derived from MediaObject
#'
#' @export
Expand Down
1 change: 1 addition & 0 deletions schema/BlockContent.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ anyOf:
- $ref: Heading
- $ref: List
- $ref: ListItem
- $ref: MathBlock
- $ref: Paragraph
- $ref: QuoteBlock
- $ref: Table
Expand Down
1 change: 1 addition & 0 deletions schema/InlineContent.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyOf:
- $ref: Emphasis
- $ref: ImageObject
- $ref: Link
- $ref: MathFragment
- $ref: Quote
- $ref: Strong
- $ref: Subscript
Expand Down
24 changes: 24 additions & 0 deletions schema/Math.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
title: Math
'@id': stencila:Math
extends: Entity
role: base
status: unstable
category: prose
description: A mathematical variable or equation.
$comment: |
This is a base type for `MathFragment` and `MathBlock` and should not
normally be instantiated.
This type has a similar structure and purpose to `Code` which is a base type
for `CodeFragment`, `CodeBlock` etc.
properties:
mathLanguage:
'@id': schema:mathLanguage
description: The language used for the equation e.g tex, mathml, asciimath.
type: string
default: 'tex'
text:
'@id': schema:text
description: The text of the equation in the language.
type: string
required:
- text
8 changes: 8 additions & 0 deletions schema/MathBlock.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: MathBlock
'@id': stencila:MathBlock
extends: Math
role: secondary
status: unstable
category: prose
description: A block of math, e.g an equation, to be treated as block content.
properties: {}
8 changes: 8 additions & 0 deletions schema/MathFragment.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: MathFragment
'@id': stencila:MathFragment
extends: Math
role: secondary
status: unstable
category: prose
description: A fragment of math, e.g a variable name, to be treated as inline content.
properties: {}

0 comments on commit 74f4b55

Please sign in to comment.