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

MCR-3111 mycore-tei datamodel and tools #2163

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions mycore-base/src/main/java/org/mycore/common/MCRConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public final class MCRConstants {

public static final Namespace MCR_NAMESPACE = Namespace.getNamespace("mcr", MCR_URL);

public static final Namespace TEI_NAMESPACE = Namespace.getNamespace("tei", "http://www.tei-c.org/ns/1.0");

private static final HashMap<String, Namespace> NAMESPACES_BY_PREFIX;

static {
Expand Down
16 changes: 0 additions & 16 deletions mycore-tei/README.md

This file was deleted.

8 changes: 8 additions & 0 deletions mycore-tei/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-base</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
15 changes: 15 additions & 0 deletions mycore-tei/src/main/datamodel/def/tei.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<objecttype name="tei" isChild="false" isParent="false" hasDerivates="true" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xsi:noNamespaceSchemaLocation="datamodel.xsd">
<xsd>
<xs:import namespace="http://www.tei-c.org/ns/1.0" schemaLocation="schema/tei_all.xsd" />
</xsd>
<metadata>
<element name="teiContainer" type="xml" style="dontknow" notinherit="true" heritable="false">
<xs:sequence>
<xs:element ref="tei:teiHeader" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be more flexible I woud make this a xs:choice of tei:teiHeader and tei:TEI

</xs:sequence>
</element>
</metadata>
</objecttype>
148 changes: 148 additions & 0 deletions mycore-tei/src/main/java/org/mycore/tei/MCRTEISplitter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package org.mycore.tei;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyCoRe License?


import java.util.ArrayList;
import java.util.List;

import org.jdom2.Attribute;
import org.jdom2.Content;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import org.mycore.common.MCRConstants;

/**
* Can split a TEI document into multiple documents based on the pb elements.
*/
public class MCRTEISplitter {

private final TeiFile original;

private Element copyTarget;

private List<TeiFile> splitDocumentList = new ArrayList<>();

private int size = -1;

public MCRTEISplitter(TeiFile original) {
this.original = original;
}

/**
* Checks if the document is splitable. A document is splitable if it contains pb elements.
* @return true if the document is splitable, false otherwise
*/
public boolean isSplitable() {
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expr = xFactory.compile("//tei:pb", Filters.element(), null,
MCRConstants.TEI_NAMESPACE);
List<Element> elementList = expr.evaluate(this.original.doc());
return !elementList.isEmpty();
}

/**
* Returns the estimated size of the split documents. This is the number of pb
* @return the estimated size of the split documents
*/
public int getEstimatedSize() {
if (size == -1) {
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expr = xFactory.compile("//tei:pb", Filters.element(), null,
MCRConstants.TEI_NAMESPACE);
List<Element> elementList = expr.evaluate(this.original.doc());
size = elementList.size();
}

return size;
}

private Stub copyAncestors(Element pbElement, String name) {
Element parent = pbElement;
Element lastClone = null;
Element firstClone = null;
while ((parent = parent.getParentElement()) != null) {
Element cloned = cloneElement(parent);
if (firstClone == null) {
firstClone = cloned;
}
if (lastClone != null) {
cloned.addContent(lastClone);
}
lastClone = cloned;
}

TeiFile teiFile = new TeiFile(name, new Document(lastClone));
this.splitDocumentList.add(teiFile);
return new Stub(firstClone, teiFile);
}

private void traverse(Element element) {
for (Content content : element.getContent()) {
if (content instanceof Element contentElement && contentElement.getName().equals("pb")) {
String facs = contentElement.getAttributeValue("facs");
if (facs.startsWith("images/")) {
facs = facs.substring("images/".length());
}
Stub newStub = copyAncestors(element, facs);
copyTarget = newStub.newEl;
continue;
}

copyToNew(content);
}
copyTarget = copyTarget.getParentElement();
}

private void copyToNew(Content content) {
if (content instanceof Element elementContent) {
Element cloned = cloneElement(elementContent);
copyTarget.addContent(cloned);

copyTarget = cloned;
traverse(elementContent);
} else {
copyTarget.addContent(content.clone());
}

}

private Element cloneElement(Element elementContent) {
Element element = new Element(elementContent.getName(), elementContent.getNamespace());
elementContent.getAttributes()
.stream()
.map(Attribute::clone)
.forEach(element::setAttribute);

return element;
}

/**
* Splits the document into multiple documents based on the pb elements.
* @return a list of the split documents
*/
public List<TeiFile> split() {
if (!splitDocumentList.isEmpty()) {
splitDocumentList = new ArrayList<>();
}

Element originalText = this.original.doc()
.getRootElement().getChild("text", MCRConstants.TEI_NAMESPACE);

Stub newStub = copyAncestors(originalText.getChildren().get(0), null);
copyTarget = newStub.newEl;

traverse(originalText);

return splitDocumentList;
}

/**
* Represents a TEI file.
*/
public record TeiFile(String name, Document doc) {
}

private record Stub(Element newEl, TeiFile teiFile) {
}
}
2 changes: 2 additions & 0 deletions mycore-tei/src/main/java/org/mycore/tei/MCRTEIValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

/**
* SAX Error handler for validating TEI XML
* @deprecated use the {@link org.mycore.datamodel.metadata.validator.MCREditorOutValidator} instead
*/
@Deprecated
public class MCRTEIValidator implements ErrorHandler {

/**
Expand Down
73 changes: 73 additions & 0 deletions mycore-tei/src/main/resources/META-INF/resources/tei/css/tei.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of *** M y C o R e ***
* See http://www.mycore.de/ for details.
*
* MyCoRe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyCoRe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

.fileSection {
margin-top: 50px;
}

.teiDisplaySection {
padding: 15px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
margin-top: 15px;
}

.possibleMatch{
margin-top: 30px;
}

.possibleMatch a {
display: block;
}

.possibleMatch b {
margin-right: 5px;
}

.teiLine {
display: block;
}

.teiRow {
display: table-row;
}

.teiCell {
display: table-cell;
padding: 5px;
}

.teiTable {
display: table;
}

dt a {

Check warning on line 60 in mycore-tei/src/main/resources/META-INF/resources/tei/css/tei.css

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

mycore-tei/src/main/resources/META-INF/resources/tei/css/tei.css#L60

Expected selector "dt a" to come before selector ".possibleMatch a" (no-descending-specificity)
vertical-align: super;
line-height: 2;
}

dt, dd {
display: inline;
font-weight: normal;
line-height: normal;
}

.popupTrigger {
cursor: pointer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of *** M y C o R e ***
* See http://www.mycore.de/ for details.
*
* MyCoRe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyCoRe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

@font-face {
font-family: 'junicode';
src: url('../webfonts/junicode/Junicode.ttf.eot');
src: url('../webfonts/junicode/Junicode.ttf?iefix') format('eot'),
url('../webfonts/junicode/Junicode.ttf.woff') format('woff'),
url('../webfonts/junicode/Junicode.ttf.svg#webfont') format('svg');
}

.transcription {
font-family: 'junicode', serif;
}

a:link {
text-decoration: none;
}

a:visited {

Check warning on line 35 in mycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

mycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css#L35

Unexpected empty block (block-no-empty)
}

a:hover {
color: #FFBF00;
}

a:active {
color: #FF0000;

Check notice on line 43 in mycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

mycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css#L43

Expected "#FF0000" to be "#F00" (color-hex-length)
}

.linebreak_none br {
display: none;
}

:target {
border: 3px solid #FFFF00;

Check notice on line 51 in mycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

mycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css#L51

Expected "#FFFF00" to be "#FF0" (color-hex-length)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a Junicode.info text or markdown file with
short description / hint on license and Github / Download URL?

Binary file not shown.
Binary file not shown.
Loading
Loading