Guido Milanese, Filologia, letteratura, computer

Aggiornamento 5 marzo 2020

1 Pagine web citate

2 Listati

Avvertenza

Vengono riprodotti tutti i listati commentati nel volume, non i singoli esempi forniti nel testo ma privi di commento. Per utilizzare gli esempi, basta effettuare un copia-incolla dei listati e salvare il testo ottenuto con un editore di testo (ad esempio vim tra i programmi professionali, oppure il semplice Blocco Note sui sistemi Windows).

2.1 HTML

<!DOCTYPE html>
<html>
<head>
  <title>Esempio</title>
</head>
<body>
<h1>Esempio di pagina codificata in HTML</h1>
  <p>Primo paragrafo: solo testo semplice.</p>
  <p>Secondo paragrafo, con una parola <em>evidenziata</em>.</p>
  <p>Terzo paragrafo, 
  contenente un link a un <a href="https://www.w3schools.com/html/">
  tutoriale per apprendere HTML</a></p>.
<!-- si tratta di un esempio davvero minimo -->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
  <title>Esempio</title>
</head>
<body>
  <h1>Esempio di pagina codificata in HTML</h1>
  <h2>Un paragrafo molto semplice</h2>
    <p>Primo paragrafo: solo testo semplice.</p>
  <h2>Un paragrafo con una parola marcata</h2>
    <p>Secondo paragrafo, con una parola <em>evidenziata</em>.</p>
  <h2>Un paragrafo con un link</h2>
   <p>Terzo paragrafo
   con link a un <a href="https://www.w3schools.com/html/">
   tutoriale per apprendere HTML</a></p>.
<!-- si tratta di un esempio davvero minimo -->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
  <title>Esempio</title>
</head>
<body>
  <h6>Esempio di pagina codificata in HTML</h6>
  <h2>Un paragrafo molto semplice</h2>
    <p>Primo paragrafo: solo testo semplice.</p>
  <h4>Un paragrafo con una parola marcata</h4>
    <p>Secondo paragrafo, con una parola <em>evidenziata</em>,
       in <i>corsivo</i>.</p>
  <h1>Un paragrafo con un link</h1>
    <p>Terzo paragrafo,
    contenente un link a un <a href="https://www.w3schools.com/html/">
    tutoriale per apprendere HTML</a></p>.
<!-- si tratta di un esempio davvero minimo -->
</body>
</html>

2.2 Markdown

Dog Breeds
==========

Bulldog breeds
--------------
_Bulldog breeds_ is a collective name for various breeds of dog of a
particular type, also known as **bull breeds**. [...]

Catch dog breeds
----------------
A _catch dog_ is a specially trained dog that is used to catch large
animals in hunting, working livestock, and baiting. [...]

Curs
----
The term _cur_ refers to the lowest class of nameless dog or _Pariah
Dog_, generally a mixed-breed dog. [...]

Dogs and Humans
===============

As pets
-------
In the 1950s and 1960s, dogs were kept outside more often than they
tend to be today [...]
<?xml version="1.0" encoding="utf-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
    <text>
        <body>
            <div type="level1">
        <head>Dog Breeds</head>
            <div type="level2">
        <head>Bulldog breeds</head>
            <p><hi rendition="simple:italic">Bulldog breeds</hi> is a
            collective name for various breeds of dog of a particular
            type, also known as <hi rendition="simple:bold">bull breeds
            </hi> . [...]</p>
            </div>
            <div type="level2">
        <head>Catch dog breeds</head>
            <p>A catch dog is a specially trained dog that is used to catch
            large animals in hunting, working livestock, and baiting.</p>
            </div>

2.3 Musica

2.3.1 MusicXML

<?xml version=’1.0’ encoding=’utf-8’?>
<!DOCTYPE score-partwise PUBLIC
"-//Recordare//DTD MusicXML 3.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<part-list>
<score-part id="P1">
<part-name />
</score-part>
</part-list>
<part id="P1">
    <measure number="1">
    <attributes>
        <divisions>120</divisions>
        <key>
            <fifths>0</fifths>
            <mode>major</mode>
        </key>
        <time>
            <beats>4</beats>
            <beat-type>4</beat-type>
        </time>
    </attributes>
    <note>
        <pitch>
            <step>C</step>
            <octave>4</octave>
        </pitch>
        <duration>120</duration>
        <voice>1</voice>
        <type>quarter</type>
    </note>
<!-- fine della prima nota -->

2.3.2 abc


X:1
M:4/4
L:1/4
K:C
CDEF | GABc | cBAG | FEDC ||

2.4 Perl

use strict;
# Contatore di capitoli e paragrafi
my $ncapitoli = 0;
my $nparagrafi = 0;
# Leggi ogni linea nella variabile $line
# e controlla se la riga s’inizia con "<chapter>" o "<p>";
# se sì, incrementa il contatore corrispondente
while(my $line = <STDIN>) {
        if($line =~ /^<chapter>/) { ++$ncapitoli; }
        if($line =~ /^<p>/) { ++$nparagrafi; }
}
print "Trovati $ncapitoli capitoli e $nparagrafi paragrafi.\n";

2.5 Prolog

% Personaggi di "Mansfield Park"
personaggio("Fanny Price").
personaggio("Tom Bertram").
personaggio("Edmund Bertram").
personaggio("Maria Bertram").
personaggio("Henry Crawford").
personaggio("Mary Crawford").
personaggio("James Rushworth").
luogo("London").
luogo("Mansfield Park").
luogo("Portsmouth").
% indicare i personaggi maschili e femminili:
donna("Fanny Price").
donna("Maria Bertram").
donna("Mary Crawford").
uomo("Tom Bertram").
uomo("Edmund Bertram").
uomo("Henry Crawford").
uomo("James Rushworth").
% Un personaggio femminile sarà tale se è personaggio e anche donna.
personaggio_femminile(X) :- personaggio(X), donna(X).

2.6 Python

# function to check if small string is there in big string
def check(string, substr):
    if (string.find(substr) == -1):
        print("NO")
    else:
        print("YES")
# driver code
string = "geeks for geeks"
substr ="geek"
check(string, substr)

2.7 Shell (bash) e linguaggi di shell

2.7.1 grep

grep array *.sno
grep -wir sonetto *
grep -r [aei]s[st][ei] * | sort

2.7.2 sort

sort dante-parole >dante-parole-ordinato
sort -k2 dante-parole >dante-parole-ordinato-2

2.7.3 sed

sed 's/Ue/Ü/g'

2.7.4 awk

#  testo di input
andare:verbo
luce:sostantivo
lentamente:avverbio
#  estrarre le voci di lessico
awk -F : '{ print $1 }'
#  estrarre la categoria morfologica
awk -F : '{ print $2 }'
#  stampare categoria e voce, separate da un trattino
awk -F : '{ print $2 "-" $1}'

2.8 Snobol

    string = "geeks for geeks"
    substring = "geek"
    ((string ? substring) (output = "YES"), (output = "NO"))
end
    Vocali = "aeiouàèéíìòùAEIOUÀÈÉÍÌÒÙ"
    Testo = input
loop Testo ? any(Vocali) . output rem . Testo :s(loop)
end

2.9 TEX, LATEX, BibTEX

2.9.1 TEX

$x^2 + y^2 = z^2$ ovvero $\sqrt{x^2 + y^2} = z$

2.9.2 LATEX

\documentclass{article}
\author{Giovanni Scrivini}
\title{\LaTeX: un esempio}
\date{5 agosto 2017}
\begin{document}
\maketitle
\section{Presentazione}
\LaTeX{} permette di scrivere documenti complessi in modo fortemente
strutturato: l’utilizzatore si concentra sul contenuto e non
sull’aspetto grafico.

\section{Uso non matematico di \LaTeX}
Nato per l’uso matematico, anche in campo umanistico si possono
ottenere grandi soddisfazioni: come è stato osservato da tempo,

\begin{quote}
  superato il momento iniziale, i risultati ottenuti con \LaTeX{}
  permettono all’umanista di liberare la scrittura dall’impostazione
  puramente grafica dei programmi di word processing.
\end{quote}

In particolare nel campo della linguistica il passaggio a questo
sistema garantisce risultati molto belli e facili da ottenere.
\end{document}

2.9.3 BibTEX

@Book{Ullman:Studies,
    Author = {Ullman, B.L.},
    Title = {Studies in the {I}talian {R}enaissance},
    Publisher = {Edizioni di Storia e Letteratura},
    Series = {Storia e Letteratura 51},
    Address = {Roma},
    Edition = {2},
    year = 1973,
    collocazione = {UC XXII-3-18},
}

2.10 XML

2.10.1 XML (fondamenti)

<?xml version="1.0" encoding="UTF-8"?>
    <scheda>
      <autore>Mirko Tavoni</autore>
      <titolo>Latino, grammatica, volgare</titolo>
      <sottotitolo>Storia di una questione umanistica</sottotitolo>
</scheda>
<scheda>
<autore>
    <cognome>Tavoni</Cognome> <!-- errore-->
    <nome>Mirko</nome>
</autore>
<titolo>Latino, grammatica, volgare<titolo>
<sottotitolo>Storia di una questione umanistica</sottotitolo>
<datoeditorale>Antenore</datoeditorale>
<datoeditorale>Padova</datoeditorale>
<datoeditorale>1984</datoeditorale>
</scheda>

2.10.2 DTD

<!ELEMENT libro (autore+,titolo,sottotitolo?,editore+,luogo+,anno,anno_riedizione*)>
<!ELEMENT autore (#PCDATA)>
<!ELEMENT titolo (#PCDATA)>
<!ELEMENT sottotitolo (#PCDATA)>
<!ELEMENT editore (#PCDATA)>
<!ELEMENT luogo (#PCDATA)>
<!ELEMENT anno (#PCDATA)>
<!ELEMENT anno_riedizione (#PCDATA)>
<!ELEMENT libro (autore+,titolo,sottotitolo?,editore+,luogo+,anno,anno_riedizione*)>
<!ELEMENT autore (nome,cognome)>
    <!ELEMENT nome (#PCDATA)>
    <!ELEMENT cognome (#PCDATA)>
<!ELEMENT titolo (#PCDATA)>
<!ELEMENT sottotitolo (#PCDATA)>
<!ELEMENT editore (#PCDATA)>
<!ELEMENT luogo (#PCDATA)>
<!ELEMENT anno (#PCDATA)>
<!ELEMENT anno_riedizione (#PCDATA)>

2.10.3 XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="libro">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="autore"/>
<xs:element ref="titolo"/>
<xs:element minOccurs="0" ref="sottotitolo"/>
<xs:element maxOccurs="unbounded" ref="editore"/>
<xs:element maxOccurs="unbounded" ref="luogo"/>
<xs:element ref="anno"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="anno_riedizione"/>
</xs:sequence>
</xs:complexType>
</xs:element>
< -- qui altri elementi -- >
</xs:schema>

2.10.4 RELAX NG

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<define name="libro">
<element name="libro">
<ref name="attlist.libro"/>
<oneOrMore>
    <ref name="autore"/>
</oneOrMore>
    <ref name="titolo"/>
<optional>
    <ref name="sottotitolo"/>
</optional>
<oneOrMore>
    <ref name="editore"/>
</oneOrMore>

2.10.5 RELAX NG compact

libro =
element libro {
    attlist.libro,
    autore+,
    titolo,
    sottotitolo?,
    editore+,
    luogo+,
    anno,
    anno_riedizione*
}
attlist.libro &= empty
autore = element autore { attlist.autore, nome, cognome }
    attlist.autore &= empty
nome = element nome { attlist.nome, text }
    attlist.nome &= empty
cognome = element cognome { attlist.cognome, text }
    attlist.cognome &= empty
titolo = element titolo { attlist.titolo, text }
    attlist.titolo &= empty
sottotitolo = element sottotitolo { attlist.sottotitolo, text }
    attlist.sottotitolo &= empty

2.10.6 TEI

<text xmlns="http://www.tei-c.org/ns/1.0" xml:id="d1">
<body xml:id="d2">
<div1 type="book" xml:id="d3">
<head>Songs of Innocence</head>
<pb n="4"/>
<div2 type="poem" xml:id="d4">
<head>Introduction</head>
<lg type="stanza">
    <l>Piping down the valleys wild, </l>
    <l>Piping songs of pleasant glee, </l>
    <l>On a cloud I saw a child, </l>
    <l>And he laughing said to me: </l>
</lg>
<lg type="stanza">
    <l>"Pipe a song about a Lamb!" </l>
    <l>So I piped with merry chear. </l>
    <l>"Piper, pipe that song again;" </l>
    <l>So I piped, he wept to hear. </l>
</lg>
</div2>

2.10.7 CSS

book {font-family: "Arial", "Helvetica", sans;
font-size: 14pt;
background-color: ivory;
}
title {display: block;
font-size: 18pt;
margin-bottom: 1cm;
}
l
{display: block;
margin-left: 8mm;
}

2.10.8 XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
 <html>
  <body style="font-family:Arial;font-size:14pt; background-color:white">
    <h1><xsl:value-of select="book/title"/></h1>
    <xsl:for-each select="book/poem/l">
    <xsl:value-of select="current()"/>
    <br></br>
    </xsl:for-each>
  </body>
 </html>
</xsl:template>
</xsl:stylesheet>