Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
c00c5309
Commit
c00c5309
authored
Sep 17, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
phpAPI: (csv index) use tfidf as score instead of sum(freq)
parent
e74b8d26
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
20 deletions
+33
-20
csv_div.php
twbackends/phpAPI/csv_div.php
+3
-3
csv_indexation.php
twbackends/phpAPI/csv_indexation.php
+24
-12
info_div.php
twbackends/phpAPI/info_div.php
+6
-4
tools.php
twbackends/phpAPI/tools.php
+0
-1
No files found.
twbackends/phpAPI/csv_div.php
View file @
c00c5309
...
...
@@ -48,7 +48,7 @@ function displayDoc($docId, $score, $base, $outmode) {
"kws"
=>
$keywords
,
"txt"
=>
$doccontent
,
"date"
=>
$date
,
"score"
=>
$score
"score"
=>
round
(
$score
,
5
)
);
}
return
$output
;
...
...
@@ -72,14 +72,14 @@ function try_attrs_until_you_find($doc_obj, $attr_names_array) {
$htmlout
=
"<ul class=infoitems>
\n
"
;
$jsonout
=
array
();
$nb_displayed
=
0
;
foreach
(
$sims
as
$doc
=>
$
freq
)
{
foreach
(
$sims
as
$doc
=>
$
score
)
{
// doc limit
if
(
$nb_displayed
>
$max_item_displayed
-
1
)
{
break
;
}
$rowid
=
ltrim
(
$doc
,
'd'
);
$thisdoc
=
displayDoc
(
$rowid
,
$
freq
,
$base
,
$output_mode
);
$thisdoc
=
displayDoc
(
$rowid
,
$
score
,
$base
,
$output_mode
);
// echodump("doc", $thisdoc);
if
(
$output_mode
==
"html"
)
{
...
...
twbackends/phpAPI/csv_indexation.php
View file @
c00c5309
...
...
@@ -49,17 +49,7 @@
// },
//
//
// The postings have the form: {
// col_i => {
// "tokenA" => {
// docid0: occs i.A.0,
// docid1: occs i.A.1,
// ...
// },
// ...
// },
// ...
// }
// The postings have the form: $nodetype => $col => $tok => $docid => $occs
//
//
//
...
...
@@ -154,8 +144,30 @@ function parse_and_index_csv($filename, $typed_cols_to_index, $separator, $quote
}
fclose
(
$fh
);
}
// post-treatment: cumulative number of docs by token
$df
=
array
()
;
for
(
$ndtypeid
=
0
;
$ndtypeid
<
$GLOBALS
[
"ntypes"
]
;
$ndtypeid
++
)
{
if
(
array_key_exists
(
$ndtypeid
,
$postings
))
{
foreach
(
$postings
[
$ndtypeid
]
as
$col
=>
$occs_matrix
)
{
foreach
(
$occs_matrix
as
$tok
=>
$doc_occs
)
{
if
(
array_key_exists
(
$tok
,
$df
))
{
$df
[
$tok
]
+=
count
(
$doc_occs
);
}
else
{
$df
[
$tok
]
=
count
(
$doc_occs
);
}
}
}
}
}
$logtotaldocs
=
log
(
$rowid
+
1
);
$idfvals
=
array
();
foreach
(
$df
as
$tok
=>
$df_tok
)
{
$idfvals
[
$tok
]
=
$logtotaldocs
-
log
(
$df_tok
);
}
return
array
(
$base
,
$postings
);
return
array
(
$base
,
$postings
,
$idfvals
);
}
...
...
twbackends/phpAPI/info_div.php
View file @
c00c5309
...
...
@@ -90,8 +90,10 @@ else {
$base
=
$csv_search_base
[
0
];
$postings
=
$csv_search_base
[
1
];
$idfvals
=
$csv_search_base
[
2
];
// echodump("postings", $postings);
// echodump("base", $base);
// echodump("idfvals", $idfvals);
// DO THE SEARCH
...
...
@@ -130,16 +132,16 @@ else {
// matches
$matching_docs
=
$searchable
[
$tok
];
foreach
(
$matching_docs
as
$doc_id
=>
$
freq
)
{
foreach
(
$matching_docs
as
$doc_id
=>
$
tf
)
{
// echodump("tok freq in this doc", $
freq
);
// echodump("tok freq in this doc", $
tf
);
// cumulated freq of tokens per doc
if
(
array_key_exists
(
$doc_id
,
$sims
))
{
$sims
[
$doc_id
]
++
;
$sims
[
$doc_id
]
+=
$tf
*
$idfvals
[
$tok
]
;
}
else
{
$sims
[
$doc_id
]
=
1
;
$sims
[
$doc_id
]
=
$tf
*
$idfvals
[
$tok
]
;
}
}
}
...
...
twbackends/phpAPI/tools.php
View file @
c00c5309
...
...
@@ -15,7 +15,6 @@ function echodump($title, $anyObj, $output_mode = "json") {
}
}
function
errmsg
(
$message
,
$context
,
$more
=
""
)
{
echo
"<p class='micromessage'>The relatedDocs DB conf for
$context
$message
(please read A-Introduction/project_config.md).<br>
$more
</p>"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment