-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
94 lines (68 loc) · 1.82 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// https://github.com/parsecsv/parsecsv-for-php
require_once("parsecsv-for-php/parsecsv.lib.php");
$csv = new ParseCsv\Csv();
$csv->encoding('UTF-16', 'UTF-8');
$csv->delimiter = ";";
$csv->parse('tableau-de-mots.csv');
// champs :
/*
Mot
Prénom
Nom
Date d'insertion
Type (nom commun, artiste, graphiste, collectif, livre, film, etc.)
Définition
Source
Prénom auteur (si le mot est une œuvre ou une citation)
Nom de famille auteur
Date de naissance et décès
Mots-clés associés (alphabétiquement)
Liens images en ligne
Éditeur
Date de création (si œuvre) ou de parution
Pays
Ville
Remarque
*/
function cmp($a, $b) {
if ( strtolower($a['Nom']) == strtolower($b['Nom']) ) {
return 0;
}
return ( strtolower($a['Nom']) < strtolower($b['Nom']) ) ? -1 : 1;
}
$texte = "";
// https://secure.php.net/manual/fr/array.sorting.php
uasort($csv->data, 'cmp');
foreach ($csv->data as $key => $ligne) {
echo $key . " => " .$ligne['Prénom'] .' '.$ligne['Nom'] ."\n";
$texte .= $ligne['Définition']." ";
}
$ponctuation = array(",", ".", ";", "'", "’", "\"", ":", "?", "!", "[", "]", "«", "»", "(", ")", "-", "_", "—", "–", "/", "\t","“","…"," ");
$texte = str_replace($ponctuation, " ", $texte);
$texte = preg_replace('/[\n]+/', " ", $texte);
$texte = preg_replace('/[ ]+/', " ", $texte);
// echo $texte;
$mots = explode(" ", $texte);
asort($mots);
// print_r($mots);
$mots3lettres = array();
foreach ($mots as $key => $mot) {
$mots[$key] = trim($mot);
}
foreach ($mots as $key => $mot) {
if(strlen($mot) >= 3){ // nombre de lettres
if( array_key_exists($mot, $mots3lettres) ){
$mots3lettres[$mot] ++;
}else{
$mots3lettres[$mot] = 1;
}
}
}
foreach ($mots3lettres as $mot => $nbr) {
if($nbr <= 1){
unset( $mots3lettres[$mot] );
}
}
asort($mots3lettres);
print_r($mots3lettres);