Continued styling.

master
Gijs 3 years ago
parent 4fd0ac3c34
commit 0c060ca841

@ -16,6 +16,8 @@ from flask import Flask, render_template, request, Response, session
from pagedjs import make_pdf
from settings import DEBUG, BASEURL, DEFAULT_LANGUAGE, SECRET_KEY
import textwrap
import os
from fcntl import lockf, LOCK_EX, LOCK_UN
@ -76,6 +78,12 @@ def get_edition_count_en():
return edition_count
def wrap (text, width):
return'\n'.join(['\n'.join(textwrap.wrap(line, width=width)) for line in text.splitlines()])
def read_sources (*paths):
return [ (p, wrap(open(p, 'r').read(), 105)) for p in paths ]
def get_language():
if 'LANGUAGE' in session:
return session['LANGUAGE']
@ -87,10 +95,38 @@ def set_language(language):
session.modified = True
def index_es():
return render_template('index.html')
context = {
BASEURL: BASEURL
}
return render_template('index.html', **context)
def index_en():
return render_template('index_en.html')
context = {
BASEURL: BASEURL
}
return render_template('index_en.html', **context)
"""
Adds the last word of the previous step to the itinerary
"""
def add_last_word_previous_step (itinerary):
new_itinerary = []
last_word_previous_step = None
for step in itinerary:
new_itinerary.append(
(
step[0],
step[1],
step[2],
step[3],
last_word_previous_step
)
)
last_word_previous_step = step[3][-1][0]
return new_itinerary
@app.route('{}/en'.format(BASEURL))
def en():
@ -125,7 +161,8 @@ def book_es ():
author = 'Benito Pérez Gáldos' # Non breaking spaces
title = 'Miau'
path = crear_camino(novel, first_word, 'es')
path = add_last_word_previous_step(crear_camino(novel, first_word, 'es'))
complete_sentence = path[-1][1] + path[-1][0]
context = {
'title': title,
@ -134,6 +171,8 @@ def book_es ():
'STATIC_DIR': '/static' if DEBUG else PAGEDJS_STATIC_DIR,
'DEBUG': DEBUG,
'edition_count': edition_count,
'sources': read_sources('paseo.py', 'medialab.py'),
'complete_sentence': complete_sentence,
}
html = render_template('book.html', **context)
@ -167,7 +206,8 @@ def book_en ():
author = 'Benito Pérez Gáldos' # Non breaking spaces
title = 'Marianela'
path = crear_camino(novel, first_word, 'en')
path = add_last_word_previous_step(crear_camino(novel, first_word, 'en'))
complete_sentence = path[-1][1] + path[-1][0]
context = {
'title': title,
@ -176,6 +216,8 @@ def book_en ():
'STATIC_DIR': '/static' if DEBUG else PAGEDJS_STATIC_DIR,
'DEBUG': DEBUG,
'edition_count': edition_count,
'sources': read_sources('paseo.py', 'medialab.py'),
'complete_sentence': complete_sentence,
}
html = render_template('book_en.html', **context)

@ -27,7 +27,7 @@ def limpiar_texto(fragmento):
fragmento_limpio = ' '.join(fragmento_limpio)
return fragmento_limpio
def crear_base_datos(nombre_texto, lenguaje='es'):
def crear_base_datos(nombre_texto, idioma='es'):
# Abrir el archivo de texto para crear la base de datos
archivo = open(nombre_texto, 'r')
fragmento = archivo.read()
@ -35,11 +35,11 @@ def crear_base_datos(nombre_texto, lenguaje='es'):
fragmento_limpio = limpiar_texto(fragmento)
# Tokenización del fragmento de texto
if lenguaje == 'es':
doc = nlp(fragmento_limpio)
if idioma == 'en':
doc = nlp_en(fragmento_limpio)
doc_len = len(doc)
else:
doc = nlp_en(fragmento_limpio)
doc = nlp(fragmento_limpio)
doc_len = len(doc)
palabras_arboles = {} #Verbos, sustantivos, adverbios y adjetivos

@ -59,7 +59,7 @@ def path(word, words_tree, words_path, trees):
# Add the current step, and the tree to the itinerary
itinerary.append((
current_step,
current_step,
previous_steps,
tree,
markov_decision_traces
@ -77,12 +77,12 @@ def path(word, words_tree, words_path, trees):
return itinerary
# Genera un camino a partir de un texto y una palabra del texto
def crear_camino(nombre_archivo, palabra_inicial, lenguaje='es'):
def crear_camino(nombre_archivo, palabra_inicial, idioma='es'):
trees = load_trees_from_json()
shuffle(trees)
#print("Starting to read text")
(palabras_arboles, palabras_camino) = crear_base_datos(nombre_archivo, lenguaje)
(palabras_arboles, palabras_camino) = crear_base_datos(nombre_archivo, idioma)
#print("Amount of tree words: ", len(palabras_arboles))

@ -0,0 +1,93 @@
Copyright (c) 2012-2013, The Mozilla Corporation and Telefonica S.A.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

@ -28,31 +28,56 @@
font-style: italic;
}
@font-face {
font-family: "Fira mono";
src: url({{ STATIC_DIR }}/fira-mono/FiraMono-Regular.ttf) format("truetype");
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: "Fira mono";
src: url({{ STATIC_DIR }}/fira-mono/FiraMono-Medium.ttf) format("truetype");
font-weight: 500;
font-style: normal;
}
@font-face {
font-family: "Fira mono";
src: url({{ STATIC_DIR }}/fira-mono/FiraMono-Bold.ttf) format("truetype");
font-weight: 600;
font-style: bold;
}
@page {
size: 210mm 297mm;
margin: 10mm 20mm 15mm 20mm;
}
@page chain {
margin: 0mm 10mm 15mm 10mm;
}
@page title {
margin: 10mm 10mm 15mm 10mm;
background: green;
margin: 10mm 10mm 15mm 10mm;
}
@page: left {
@page:left {
@bottom-left {
text-align: left;
content: counter(page);
}
}
@page: right {
@page:right {
@bottom-right {
text-align: right;
content: counter(page);
}
}
@page: empty {
@page:empty {
@bottom-right {
content: '';
}
@ -72,7 +97,10 @@
}
}
#chapter-chain {
page: chain;
}
:root {
--font-size: 10pt;
--line-height: 15pt;
@ -85,11 +113,6 @@
line-height: var(--line-height);
}
ul {
margin: 0;
padding: 0;
}
h1 {
page: title;
color: white;
@ -105,6 +128,24 @@
font-style: normal;
}
h2 {
font-family: Serreria;
font-size: 18pt;
line-height: 24pt;
}
ul {
margin: 0 0 0 1.1em;
padding: 0;
list-style-type: none;
}
ul li:before {
content: ' ';
position: absolute;
margin-left: -1.1em;
}
section.step {
page-break-before: always;
text-align: center;
@ -114,6 +155,10 @@
padding: 0;
}
section.step.first {
page-break-before: right;
}
section.step_content {
overflow: hidden;
position: absolute;
@ -150,6 +195,11 @@
padding: 0;
}
.traces li:before,
.options li:before {
content: '';
}
.sentence {
z-index: 1;
position: absolute;
@ -162,7 +212,6 @@
/* background: white; */
}
.tree {
z-index: 1;
position: absolute;
@ -182,6 +231,10 @@
/* font-style: italic; */
}
.last-word-previous-step [data-picked] {
text-decoration: none;
}
[data-picked]::after {
content: ' → ';
text-decoration: none;
@ -195,6 +248,90 @@
.traces> :last-child [data-picked]::after {
display: none;
}
.chapter {
page-break-before: right;
}
.chapter#chapter-introduction,
.chapter#chapter-description,
.chapter#chapter-technical-description,
.chapter#chapter-credits {
width: 65%;
}
.pagedjs_right_page .chapter#chapter-introduction,
.pagedjs_right_page .chapter#chapter-description,
.pagedjs_right_page .chapter#chapter-technical-description,
.pagedjs_right_page .chapter#chapter-credits {
margin-left: 30%;
}
.pagedjs_right_page .sources {
float: left;
margin-left: calc(-1 * (40% + 3em));
width: 40%;
}
.pagedjs_left_page .sources {
float: left;
margin-right: calc(-1 * (100% + 3em));
width: 40%;
}
.sources a {
word-break: break-all;
}
a {
text-decoration: underline dotted;
color: currentColor;
}
pre, code, table {
font-family: "Fira mono";
font-size: .8rem;
}
th {
font-weight: normal;
}
h4 {
font-size: 1rem;
}
h4:first-child {
margin-top: 0;
}
.pagedjs_right_page p.images {
margin-left: -25%;
}
.pagedjs_left_page p.images {
margin-right: -25%;
}
img {
display: inline-block;
max-width: 45%;
vertical-align: top;
}
.complete_sentence {
height: 282mm;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
page-break-before: right;
page-break-after: left;
padding-left: 15mm;
padding-right: 15mm;
}
</style>
{% if DEBUG %}
<link href="{{ STATIC_DIR }}/pagedjs-interface.css" rel="stylesheet" type="text/css">
@ -205,7 +342,47 @@
<body>
<h1>Paseo por los árboles de Madrid con&nbsp;<em>{{ author }}</em> y&nbsp;{{ title }}</h1>
<section class="chapter">
<section class="chapter" id="chapter-chain">
<h2 id="poema-paseo">Paseo por los árboles de Madrid con&nbsp;<em>{{ author }}</em> y&nbsp;{{ title }}</h2>
{% for sentence, previous_steps, tree, traces, last_word_previous_step in path %}
<section class="step{% if loop.first %} first{% endif %}">
<section class="sentence">
{{ previous_steps }}
</section>
<section class="step_content">
<ul class="traces">
{% if last_word_previous_step %}
<li class="last-word-previous-step">
<ul class="options">
<li data-picked>{{ last_word_previous_step}}</li>
</ul>
</li>
{% endif %}
{% for word, dice, options in traces %}
<li style="margin-top: calc(-{{ dice }} * var(--line-height))">
<ul class="options">
{% for option in options %}
<li {% if loop.index0==dice %}data-picked{% endif %}>
{{ option }}
</li>
{% endfor %}
</ul>
<!-- Rolled: {{ dice }} -->
</li>
{% endfor %}
</ul>
</section>
<section class="tree">
{{ tree.properties.NOMBRE_COMUN }} en {{ tree.properties.MINTDIRECCIONAUX }}
</section>
</section>
{% endfor %}
<section class="complete_sentence">
{{ complete_sentence }}
</section>
</section>
<section class="chapter" id="chapter-introduction">
<h2 id="introducci-n">Introducción</h2>
<p>Paseo por los árboles de Madrid es un libro en la <em>Editorial Algoliteraria: crear alianzas con los
árboles</em>.<br>El autor de este libro es el algoritmo de las cadenas de Markov. Genera simultáneamente
@ -244,45 +421,26 @@
</ul>
</section>
{% for sentence, previous_steps, tree, traces in path %}
<section class="step">
<h2 id="poema-paseo">Poema &amp; Paseo</h2>
<section class="sentence">
{{ previous_steps }}
</section>
<section class="step_content">
<ul class="traces">
{% for word, dice, options in traces %}
<li style="margin-top: calc(-{{ dice }} * var(--line-height))">
<ul class="options">
{% for option in options %}
<li {% if loop.index0==dice %}data-picked{% endif %}>
{{ option }}
</li>
{% endfor %}
</ul>
<!-- Rolled: {{ dice }} -->
<section class="chapter" id="chapter-description">
<h2 id="descripci-n-general-de-las-cadenas-de-markov">Descripción general de las cadenas de Markov</h2>
<section class="sources">
<h4 id="fuentes">Fuentes</h4>
<ul>
<li>
<a
href="https://spectrum.ieee.org/andrey-markov-and-claude-shannon-built-the-first-language-generation-models">https://spectrum.ieee.org/andrey-markov-and-claude-shannon-built-the-first-language-generation-models</a>
</li>
<li><a href="http://langvillea.people.cofc.edu/MCapps7.pdf">http://langvillea.people.cofc.edu/MCapps7.pdf</a></li>
<li>
<a
href="https://www.irishtimes.com/news/science/that-s-maths-andrey-markov-s-brilliant-ideas-are-still-bearing-fruit-1.3220929">https://www.irishtimes.com/news/science/that-s-maths-andrey-markov-s-brilliant-ideas-are-still-bearing-fruit-1.3220929</a>
</li>
<li>
<a
href="http://www.alpha60.de/research/markov/DavidLink_TracesOfTheMouth_2006.pdf">http://www.alpha60.de/research/markov/DavidLink_TracesOfTheMouth_2006.pdf</a>
</li>
{% endfor %}
</ul>
</section>
<section class="tree">
{{ tree.properties.NOMBRE_COMUN }} en {{ tree.properties.MINTDIRECCIONAUX }}
</section>
</section>
{% endfor %}
<section class="chapter">
<h2 id="descripci-n-general-de-las-cadenas-de-markov">Descripción general de las cadenas de Markov</h2>
<h4 id="fuentes">Fuentes</h4>
<p><a
href="https://spectrum.ieee.org/andrey-markov-and-claude-shannon-built-the-first-language-generation-models">https://spectrum.ieee.org/andrey-markov-and-claude-shannon-built-the-first-language-generation-models</a>
<a href="http://langvillea.people.cofc.edu/MCapps7.pdf">http://langvillea.people.cofc.edu/MCapps7.pdf</a>
<a
href="https://www.irishtimes.com/news/science/that-s-maths-andrey-markov-s-brilliant-ideas-are-still-bearing-fruit-1.3220929">https://www.irishtimes.com/news/science/that-s-maths-andrey-markov-s-brilliant-ideas-are-still-bearing-fruit-1.3220929</a>
<a
href="http://www.alpha60.de/research/markov/DavidLink_TracesOfTheMouth_2006.pdf">http://www.alpha60.de/research/markov/DavidLink_TracesOfTheMouth_2006.pdf</a>
</p>
<h3 id="historias">Historias</h3>
<p>Andrey Andreyevich Markov fue un matemático ruso que vivió entre 1856 y 1922. Sus estudios más famosos fueron
con las cadenas de Markov, un algoritmo que permite predecir los cambios futuros una vez que se conoce el
@ -328,9 +486,10 @@
Aunque Markov hubiera tenido más tiempo y mejor vista para llevar a cabo sus experimentos, las extensiones
habrían sido muy difíciles de completar, dada la época preinformática en la que vivió, en la que los
esfuerzos computacionales debían pagarse en años-hombre. </p>
<p><img src="markov_1.jpeg" alt="">
<img src="markov_2.jpeg" alt=""><br>These images show Markovs original notes in computing the probabilities
needed for his Pushkin chain.
<p class="images"><img src="{{ STATIC_DIR }}/images/markov_1.jpeg" alt="">
<img src="{{ STATIC_DIR }}/images/markov_2.jpeg" alt=""><br>
Estas imágenes muestran las notas originales de Markov al calcular las probabilidades necesarias para su
cadena Pushkin.
</p>
<h3 id="influencia">Influencia</h3>
<p>Algunos de los conceptos centrales de Markov en torno a la probabilidad y el lenguaje se extendieron por el
@ -402,16 +561,25 @@
También aquí las cadenas de Markov han asumido gran parte del trabajo. </p>
</section>
<section class="chapter">
<section class="chapter" id="chapter-technical-description">
<h2 id="descripci-n-t-cnica-de-las-cadenas-de-markov">Descripción técnica de las cadenas de Markov</h2>
<h4 id="sources-">Fuentes:</h4>
<p><a
href="https://en.wikipedia.org/wiki/Examples_of_Markov_chains">https://en.wikipedia.org/wiki/Examples_of_Markov_chains</a>
<a
href="https://higherkindedtripe.wordpress.com/2012/02/26/markov-chains-or-daddy-where-does-spam-come-from/">https://higherkindedtripe.wordpress.com/2012/02/26/markov-chains-or-daddy-where-does-spam-come-from/</a>
<a
href="https://towardsdatascience.com/predicting-the-weather-with-markov-chains-a34735f0c4df">https://towardsdatascience.com/predicting-the-weather-with-markov-chains-a34735f0c4df</a>
</p>
<section class="sources">
<h4>Fuentes:</h4>
<ul>
<li>
<a
href="https://en.wikipedia.org/wiki/Examples_of_Markov_chains">https://en.wikipedia.org/wiki/Examples_of_Markov_chains</a>
</li>
<li>
<a
href="https://higherkindedtripe.wordpress.com/2012/02/26/markov-chains-or-daddy-where-does-spam-come-from/">https://higherkindedtripe.wordpress.com/2012/02/26/markov-chains-or-daddy-where-does-spam-come-from/</a>
</li>
<li>
<a
href="https://towardsdatascience.com/predicting-the-weather-with-markov-chains-a34735f0c4df">https://towardsdatascience.com/predicting-the-weather-with-markov-chains-a34735f0c4df</a>
</li>
</ul>
</section>
<p>En un proceso de Markov podemos predecir los cambios futuros una vez que conocemos el estado actual.
Wikipedia describe muy bien la diferencia entre las cadenas de Markov y otros sistemas: &quot;Un juego de
serpientes y escaleras o cualquier otro juego cuyas jugadas se determinan enteramente por los dados es una
@ -751,12 +919,15 @@
</blockquote>
</section>
<section class="chapter">
<h2 id="c-digo">Código</h2>
<!-- VOEG CODE TOE-->
<section class="chapter" id="chapter-code">
<h2 id="c-digo">Código</h2>
{% for path, source in sources %}
<h3>{{ path }}</h3>
<pre>{{ source }}</pre>
{% endfor %}
</section>
<section class="chapter">
<section class="chapter" id="chapter-credits">
<h2 id="cr-ditos">Créditos</h2>
<p>Este libro es una creación de Anaïs Berck para Medialab como parte del programa &quot;Residencia Cultura
Digital&quot; iniciado por el Gobierno Flamenco.<br>En esta obra Anaïs Berck está representadx por:</p>

File diff suppressed because it is too large Load Diff

@ -68,6 +68,15 @@
font-size: 34pt;
line-height: 45pt;
margin-top: 0;
margin-bottom: 0;
}
a {
color: currentColor;
}
a:hover {
text-decoration: none;
}
p {
@ -157,7 +166,10 @@
</style>
</head>
<body>
<h1 id="title">Paseo por los árboles de Madrid</h1>
<section id="title">
<h1 id="title">Paseo por los árboles de Madrid</h1>
<a href="{{ BASEURL }}/en">en</a>
</section>
<section id="introduction">
<p>En este libro, el algoritmo de las cadenas de Markov genera simultáneamente un poema y un paseo por los árboles del barrio de Las Letras, en el centro de Madrid. A pesar de la impresión de que hay pocos árboles en el barrio, el algoritmo cuenta con 460 de ellos. </p>
<p>La cadena de Markov fue diseñada en 1906 por Andrey Markov, un matemático ruso fallecido en 1992. Este algoritmo está en la base de muchos programas informáticos que generan spam. Se utiliza para sistemas que describen una serie de eventos que son interdependientes. Lo que ocurre depende únicamente del paso anterior.</p>

@ -68,6 +68,15 @@
font-size: 34pt;
line-height: 45pt;
margin-top: 0;
margin-bottom: 0;
}
a {
color: currentColor;
}
a:hover {
text-decoration: none;
}
p {
@ -157,7 +166,10 @@
</style>
</head>
<body>
<h1 id="title">Walk along the trees of Madrid</h1>
<div id="title">
<h1>Walk along the trees of Madrid</h1>
<a href="{{ BASEURL }}/es">es</a>
</div>
<section id="introduction">
<p>In this book, the Markov chain algorithm simultaneously generates a poem and a walk along the trees of the neighbourhood Las Letras in the centre of Madrid. Despite the impression that there are few trees in the neighbourhood, the algorithm counts 460 of them.</p>
<p>The Markov chain was designed in 1906 by Andrey Markov, a Russian mathematician who died in 1992. This algorithm is at the basis of many computer programs that generate spam. It is used for systems that describe a series of events that are interdependent. What happens depends only on the previous step.</p>

Loading…
Cancel
Save