[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qsos-commits] qsos/apps/o3s/libs QSOSDocument.php
From: |
Raphaël Semeteys |
Subject: |
[Qsos-commits] qsos/apps/o3s/libs QSOSDocument.php |
Date: |
Sun, 17 May 2009 22:39:35 +0000 |
CVSROOT: /sources/qsos
Module name: qsos
Changes by: Raphaël Semeteys <rsemeteys> 09/05/17 22:39:35
Modified files:
apps/o3s/libs : QSOSDocument.php
Log message:
Better weight rendering (no division by zero, etc.)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/o3s/libs/QSOSDocument.php?cvsroot=qsos&r1=1.1&r2=1.2
Patches:
Index: QSOSDocument.php
===================================================================
RCS file: /sources/qsos/qsos/apps/o3s/libs/QSOSDocument.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- QSOSDocument.php 2 Feb 2007 07:18:21 -0000 1.1
+++ QSOSDocument.php 17 May 2009 22:39:35 -0000 1.2
@@ -42,8 +42,9 @@
var $doc;
var $xpath;
- //$file: filename of the QSOS document to load
+ //$file: filename (or URI) of the QSOS document to load
function __construct($file) {
+ //if (file_exists($file) ||
(strpos(current(get_headers($file)), "OK"))) {
if (file_exists($file)) {
$this->doc = new DOMDocument();
$this->doc->load($file);
@@ -262,6 +263,7 @@
for ($i=0; $i < count($tree); $i++) {
$name = $tree[$i]->name;
$weight = $weights[$name];
+ if (!isset($weight)) $weight = 1;
$totalWeight = $totalWeight + $weight;
if ($tree[$i]->score == null) {
$isRenderable = false;
@@ -269,9 +271,22 @@
$sum += round(($tree[$i]->score)*$weight, 2);
}
+ if ($totalWeight == 0) return 0;
$score = round(($sum/$totalWeight), 2);
return $score;
}
+
+ //$element: name of the XML element to count
+ //Returns: number of XML element occurences
+ public function getcountkey($element) {
+ return $this->xpath->evaluate("count(//$element)");
+ }
+
+ //$element: name of the XML element to count
+ //Returns: number of XML element occurences
+ public function getdeep() {
+ return $this->xpath->evaluate("count(element/element)");
+ }
}
?>
\ No newline at end of file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qsos-commits] qsos/apps/o3s/libs QSOSDocument.php,
Raphaël Semeteys <=