-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.php
More file actions
78 lines (60 loc) · 2.11 KB
/
import.php
File metadata and controls
78 lines (60 loc) · 2.11 KB
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
<pre>
<?php
require_once 'dao.php';
$dbname = "m2r_info";
$login = "root";
$password = "root";
$bdd = new PDO('mysql:host=localhost;dbname='.$dbname, $login, $password);
function enregistreArticle($val, $bdd) {
$req = $bdd->prepare("INSERT INTO articles (titre, datea, journal, auteurs, abstract, keywords) VALUES (:titre, :datea, :journal, :auteurs, :abstract, :keywords)");
$req->execute(array(
"titre" => $val['titre'],
"datea" => $val['datea'],
"journal" => $val['journal'],
"auteurs" => join(",", $val['auteurs']),
"abstract" => $val['abstract'],
"keywords" => $val['keywords']
));
}
$file_handle = fopen("outputacm.txt", "r");
$article = array('titre' => "", 'datea' => "", 'journal' => "", 'auteurs' => "", 'abstract' => "", 'keywords' => "");
$i = 0;
while (!feof($file_handle) && $i < 5000) {
$line = fgets($file_handle);
if ($line == "\n") {
enregistreArticle($article, $bdd);
$article = array('titre' => "", 'datea' => "", 'journal' => "", 'auteurs' => "", 'abstract' => "", 'keywords' => "");
$i++;
} else {
switch (str_split($line, 2)[0]) {
case '#*':
$article['titre'] = explode("#*", $line)[1];
break;
case '#t':
$article['date'] = explode("#t", $line)[1];
break;
case '#c':
$article['journal'] = explode("#c", $line)[1];
break;
case '#@':
$t_auteurs = explode("#@", $line)[1];
$article['auteurs'] = explode(',', $t_auteurs);
break;
case '#!':
$article['abstract'] = explode("#!", $line)[1];
break;
default:
// code...
break;
}
$article['keywords'] = array_diff(explode(' ', strtolower($article['titre']).' '.strtolower($article['abstract'])), DAO::getStopWords());
foreach ($article['keywords'] as $key => $value) {
$article['keywords'][$key] = trim($article['keywords'][$key], ':,;-?!(){}[]_=+');
}
$article['keywords'] = implode(',' ,$article['keywords']);
//print_r($article);
}
}
fclose($file_handle);
?>
</pre>