-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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" /> | ||
</xs:sequence> | ||
</element> | ||
</metadata> | ||
</objecttype> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* 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/>. | ||
*/ | ||
|
||
package org.mycore.tei; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
} | ||
} |
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 Codacy Production / Codacy Static Code Analysismycore-tei/src/main/resources/META-INF/resources/tei/css/tei.css#L60
|
||
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 Codacy Production / Codacy Static Code Analysismycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css#L35
|
||
} | ||
|
||
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 Codacy Production / Codacy Static Code Analysismycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css#L43
|
||
} | ||
|
||
.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 Codacy Production / Codacy Static Code Analysismycore-tei/src/main/resources/META-INF/resources/tei/css/webfont-junicode.css#L51
|
||
} |
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.
to be more flexible I woud make this a xs:choice of tei:teiHeader and tei:TEI