Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iDOIne
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gael Picot
iDOIne
Commits
9926ae68
Commit
9926ae68
authored
1 year ago
by
Gael PICOT
Browse files
Options
Downloads
Patches
Plain Diff
séparation search en Search, Result et Results
parent
6e85ac61
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
search/Result.php
+147
-0
147 additions, 0 deletions
search/Result.php
search/Results.php
+152
-0
152 additions, 0 deletions
search/Results.php
search/Search.php
+8
-246
8 additions, 246 deletions
search/Search.php
with
307 additions
and
246 deletions
search/Result.php
0 → 100644
+
147
−
0
View file @
9926ae68
<?php
namespace
uga\idoine\search
;
use
stdClass
;
require_once
dirname
(
__FILE__
,
2
)
.
DIRECTORY_SEPARATOR
.
'vendor/autoload.php'
;
/**
*
* Resultat d'une recherche sur une des divers API de recherche.
*
* @author Gaël PICOT
*
* iDOIne :
* Copyright (C) 2022 UGA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/**
* Décrit un élément trouver
*/
class
Result
{
/**
* URL vers le résultat
*
* @var string
*/
private
string
$URL
;
/**
* Le DOI trouvé
*
* @var string
*/
private
string
$DOI
;
/**
* Liste des noms des auteurs
*
* @var array
*/
private
array
$authors
;
/**
* Titre principal trouver
*
* @var string
*/
private
string
$title
;
/**
* Journal de publication
*
* @var string
*/
private
string
$journal
;
/**
* Date de publication
*
* @var string
*/
private
string
$publicationDate
;
/**
* Avertissement
*
* @var string
*/
private
string
$warning
;
/**
* Ressemblance avec le titre de la publication Hal en pourcentage.
*
* @var float
*/
private
float
$scorePercent
=
0
;
/**
* Constructeur
*
* @param stdClass $data
*/
public
function
__construct
(
stdClass
$data
)
{
$this
->
URL
=
(
isset
(
$data
->
URL
))
?
$data
->
URL
:
''
;
$this
->
DOI
=
(
isset
(
$data
->
DOI
))
?
$data
->
DOI
:
''
;
$this
->
authors
=
(
isset
(
$data
->
authors
))
?
$data
->
authors
:
[];
$this
->
title
=
(
isset
(
$data
->
title
))
?
$data
->
title
:
''
;
$this
->
publicationDate
=
(
isset
(
$data
->
publicationDate
))
?
$data
->
publicationDate
:
''
;
$this
->
journal
=
(
isset
(
$data
->
journal
))
?
$data
->
journal
:
''
;
$this
->
warning
=
(
isset
(
$data
->
warning
))
?
$data
->
warning
:
''
;
}
/**
* Accesseur pour le titre
*
* @return string
*/
public
function
getTitle
():
string
{
return
$this
->
title
;
}
/**
* Revoie le résultat sous forme d'une string JSON.
*
* @return string
*/
public
function
toJSON
():
string
{
return
json_encode
(
$this
->
toArray
());
}
/**
* Construi un tableau représentant le resultat.
*
* @return array
*/
public
function
toArray
():
array
{
$data
=
[
'URL'
=>
$this
->
URL
,
'DOI'
=>
$this
->
DOI
,
'authors'
=>
$this
->
authors
,
'title'
=>
$this
->
title
,
'journal'
=>
$this
->
journal
,
'publicationDate'
=>
$this
->
publicationDate
,
'scorePercent'
=>
$this
->
scorePercent
,
'warning'
=>
$this
->
warning
];
return
$data
;
}
/**
* Modiffieur de $scorePercent
*
* @param float $scorePercent
* @return void
*/
public
function
setScorePercent
(
float
$scorePercent
)
{
$this
->
scorePercent
=
$scorePercent
;
}
}
This diff is collapsed.
Click to expand it.
search/Results.php
0 → 100644
+
152
−
0
View file @
9926ae68
<?php
namespace
uga\idoine\search
;
use
stdClass
;
require_once
dirname
(
__FILE__
,
2
)
.
DIRECTORY_SEPARATOR
.
'vendor/autoload.php'
;
/**
*
* Ensemble de Resultats d'une recherche sur une des divers API de recherche.
*
* @author Gaël PICOT
*
* iDOIne :
* Copyright (C) 2022 UGA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/**
* Décrit les résultats d'une recherche
*/
class
Results
{
/**
* Document Hal objet de la recherche
*
* @var string
*/
private
string
$halid
;
/**
* Donnée extraite de Hal au sujet du document chercher
*
* @var stdClass|null
*/
private
?stdClass
$halData
=
null
;
/**
* Liste des résultats trouver
*
* @var array
*/
private
array
$resultList
=
[];
/**
* Meilleur score
*
* @var float
*/
private
float
$bestScore
=
0
;
/**
* Meilleur résultat trouver
*
* @var Result|null
*/
private
?Result
$bestResult
=
null
;
/**
* Meilleur score résultat en poursentage
*
* @var integer
*/
private
int
$bestScorePersent
=
0
;
/**
* Charge les donnée à partir de l'API Hal
*
* @param string $fl liste des champs cherché dans l'API HAl.
* @return stdClass
*/
public
function
getHalData
(
string
$fl
=
'title_s,journalTitle_s'
):
stdClass
{
if
(
$this
->
halData
==
null
)
{
$halQuery
=
"https://api.archives-ouvertes.fr/search/?q=halId_s%3A"
.
$this
->
halid
.
"&fl="
.
$fl
;
$this
->
halData
=
json_decode
(
file_get_contents
(
$halQuery
))
->
response
->
docs
[
0
];
}
return
$this
->
halData
;
}
/**
* Accés au titres Hal
*
* @return array
*/
public
function
getHalTitles
():
array
{
return
$this
->
getHalData
()
->
title_s
;
}
/**
* Constructeur
*
* @param string $halid
*/
public
function
__construct
(
string
$halid
)
{
$this
->
halid
=
$halid
;
}
/**
* Ajouté un résultat
*
* @param Result $newResult
* @return void
*/
public
function
addResult
(
Result
$newResult
)
{
array_push
(
$this
->
resultList
,
$newResult
);
$percent
=
0
;
$score
=
similar_text
(
strtolower
(
$this
->
getHalTitles
()[
0
]),
strtolower
(
$newResult
->
getTitle
()),
$percent
);
$newResult
->
setScorePercent
(
$percent
);
if
(
$score
>
$this
->
bestScore
||
$this
->
bestScore
==
0
)
{
$this
->
bestResult
=
$newResult
;
$this
->
bestScore
=
$score
;
}
}
/**
* Construit une représentaion sous forme de tableau.
*
* @return array
*/
public
function
toArray
():
array
{
$data
=
[
'bestScorePercent'
=>
(
isset
(
$this
->
bestScorePersent
))
?
$this
->
bestScorePersent
:
0
,
'resultList'
=>
[],
];
if
(
$this
->
bestResult
!=
null
)
{
$data
[
'bestResult'
]
=
$this
->
bestResult
->
toArray
();
}
foreach
(
$this
->
resultList
as
$result
){
array_push
(
$data
[
'resultList'
],
$result
->
toArray
());
}
return
$data
;
}
/**
* Construit une représentaion au format JSON
*
* @return string
*/
public
function
toJSON
():
string
{
return
json_encode
(
$this
->
toArray
());
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
search/Search.php
+
8
−
246
View file @
9926ae68
...
...
@@ -2,9 +2,16 @@
namespace
uga\idoine\search
;
use
uga\hallib\OneDocQuery
;
use
uga\hallib\queryDefinition\LiteralElement
;
use
uga\hallib\search\SearchField
;
use
uga\hallib\search\SearchQuery
;
require_once
dirname
(
__FILE__
,
2
)
.
DIRECTORY_SEPARATOR
.
'vendor/autoload.php'
;
/**
*
*
Commun au divers API de recherch
e
*
Recherche d'un document Hal dans d'autre servic
e
*
* @author Gaël PICOT
*
...
...
@@ -26,14 +33,6 @@ namespace uga\idoine\search;
*
*/
use
stdClass
;
use
uga\hallib\OneDocQuery
;
use
uga\hallib\queryDefinition\LiteralElement
;
use
uga\hallib\search\SearchField
;
use
uga\hallib\search\SearchQuery
;
require_once
dirname
(
__FILE__
,
2
)
.
DIRECTORY_SEPARATOR
.
'vendor/autoload.php'
;
/**
* Recherche d'un document Hal dans d'autre service (CrossRef...)
*/
...
...
@@ -201,240 +200,3 @@ class Search {
}
}
/**
* Décrit un élément trouver
*/
class
Result
{
/**
* URL vers le résultat
*
* @var string
*/
private
string
$URL
;
/**
* Le DOI trouvé
*
* @var string
*/
private
string
$DOI
;
/**
* Liste des noms des auteurs
*
* @var array
*/
private
array
$authors
;
/**
* Titre principal trouver
*
* @var string
*/
private
string
$title
;
/**
* Journal de publication
*
* @var string
*/
private
string
$journal
;
/**
* Date de publication
*
* @var string
*/
private
string
$publicationDate
;
/**
* Avertissement
*
* @var string
*/
private
string
$warning
;
/**
* Ressemblance avec le titre de la publication Hal en pourcentage.
*
* @var float
*/
private
float
$scorePercent
=
0
;
/**
* Constructeur
*
* @param stdClass $data
*/
public
function
__construct
(
stdClass
$data
)
{
$this
->
URL
=
(
isset
(
$data
->
URL
))
?
$data
->
URL
:
''
;
$this
->
DOI
=
(
isset
(
$data
->
DOI
))
?
$data
->
DOI
:
''
;
$this
->
authors
=
(
isset
(
$data
->
authors
))
?
$data
->
authors
:
[];
$this
->
title
=
(
isset
(
$data
->
title
))
?
$data
->
title
:
''
;
$this
->
publicationDate
=
(
isset
(
$data
->
publicationDate
))
?
$data
->
publicationDate
:
''
;
$this
->
journal
=
(
isset
(
$data
->
journal
))
?
$data
->
journal
:
''
;
$this
->
warning
=
(
isset
(
$data
->
warning
))
?
$data
->
warning
:
''
;
}
/**
* Accesseur pour le titre
*
* @return string
*/
public
function
getTitle
():
string
{
return
$this
->
title
;
}
/**
* Revoie le résultat sous forme d'une string JSON.
*
* @return string
*/
public
function
toJSON
():
string
{
return
json_encode
(
$this
->
toArray
());
}
/**
* Construi un tableau représentant le resultat.
*
* @return array
*/
public
function
toArray
():
array
{
$data
=
[
'URL'
=>
$this
->
URL
,
'DOI'
=>
$this
->
DOI
,
'authors'
=>
$this
->
authors
,
'title'
=>
$this
->
title
,
'journal'
=>
$this
->
journal
,
'publicationDate'
=>
$this
->
publicationDate
,
'scorePercent'
=>
$this
->
scorePercent
,
'warning'
=>
$this
->
warning
];
return
$data
;
}
/**
* Modiffieur de $scorePercent
*
* @param float $scorePercent
* @return void
*/
public
function
setScorePercent
(
float
$scorePercent
)
{
$this
->
scorePercent
=
$scorePercent
;
}
}
/**
* Décrit les résultats d'une recherche
*/
class
Results
{
/**
* Document Hal objet de la recherche
*
* @var string
*/
private
string
$halid
;
/**
* Donnée extraite de Hal au sujet du document chercher
*
* @var stdClass|null
*/
private
?stdClass
$halData
=
null
;
/**
* Liste des résultats trouver
*
* @var array
*/
private
array
$resultList
=
[];
/**
* Meilleur score
*
* @var float
*/
private
float
$bestScore
=
0
;
/**
* Meilleur résultat trouver
*
* @var Result|null
*/
private
?Result
$bestResult
=
null
;
/**
* Meilleur score résultat en poursentage
*
* @var integer
*/
private
int
$bestScorePersent
=
0
;
/**
* Charge les donnée à partir de l'API Hal
*
* @param string $fl liste des champs cherché dans l'API HAl.
* @return stdClass
*/
public
function
getHalData
(
string
$fl
=
'title_s,journalTitle_s'
):
stdClass
{
if
(
$this
->
halData
==
null
)
{
$halQuery
=
"https://api.archives-ouvertes.fr/search/?q=halId_s%3A"
.
$this
->
halid
.
"&fl="
.
$fl
;
$this
->
halData
=
json_decode
(
file_get_contents
(
$halQuery
))
->
response
->
docs
[
0
];
}
return
$this
->
halData
;
}
/**
* Accés au titres Hal
*
* @return array
*/
public
function
getHalTitles
():
array
{
return
$this
->
getHalData
()
->
title_s
;
}
/**
* Constructeur
*
* @param string $halid
*/
public
function
__construct
(
string
$halid
)
{
$this
->
halid
=
$halid
;
}
/**
* Ajouté un résultat
*
* @param Result $newResult
* @return void
*/
public
function
addResult
(
Result
$newResult
)
{
array_push
(
$this
->
resultList
,
$newResult
);
$percent
=
0
;
$score
=
similar_text
(
strtolower
(
$this
->
getHalTitles
()[
0
]),
strtolower
(
$newResult
->
getTitle
()),
$percent
);
$newResult
->
setScorePercent
(
$percent
);
if
(
$score
>
$this
->
bestScore
||
$this
->
bestScore
==
0
)
{
$this
->
bestResult
=
$newResult
;
$this
->
bestScore
=
$score
;
}
}
/**
* Construit une représentaion sous forme de tableau.
*
* @return array
*/
public
function
toArray
():
array
{
$data
=
[
'bestScorePercent'
=>
(
isset
(
$this
->
bestScorePersent
))
?
$this
->
bestScorePersent
:
0
,
'resultList'
=>
[],
];
if
(
$this
->
bestResult
!=
null
)
{
$data
[
'bestResult'
]
=
$this
->
bestResult
->
toArray
();
}
foreach
(
$this
->
resultList
as
$result
){
array_push
(
$data
[
'resultList'
],
$result
->
toArray
());
}
return
$data
;
}
/**
* Construit une représentaion au format JSON
*
* @return string
*/
public
function
toJSON
():
string
{
return
json_encode
(
$this
->
toArray
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment