Modified:
/trunk/moriarty.inc.php
/trunk/simplegraph.class.php
/trunk/tests/simplegraph.test.php
=======================================
--- /trunk/moriarty.inc.php Fri Sep 9 05:55:33 2011
+++ /trunk/moriarty.inc.php Thu Jan 12 01:59:37 2012
@@ -39,6 +39,7 @@
define('RDFS_LABEL', 'http://www.w3.org/2000/01/rdf-schema#label');
define('RDFS_COMMENT', 'http://www.w3.org/2000/01/rdf-schema#comment');
define('RDFS_ISDEFINEDBY', 'http://www.w3.org/2000/01/rdf-schema#isDefinedBy');
+define('OV_DEFINES', 'http://open.vocab.org/terms/defines');
define('RDFS_DOMAIN', 'http://www.w3.org/2000/01/rdf-schema#domain');
define('RDFS_RANGE', 'http://www.w3.org/2000/01/rdf-schema#range');
define('RDFS_SEEALSO', 'http://www.w3.org/2000/01/rdf-schema#seeAlso');
@@ -70,6 +71,8 @@
define('DC_DATE', 'http://purl.org/dc/elements/1.1/date');
define('DCT_ABSTRACT', 'http://purl.org/dc/terms/abstract');
+define('DCT_HASPART', 'http://purl.org/dc/terms/hasPart');
+define('DCT_ISPARTOF', 'http://purl.org/dc/terms/isPartOf');
define('DCT_PROVENANCE', 'http://purl.org/dc/terms/provenance');
define('OS_STARTINDEX','http://a9.com/-/spec/opensearch/1.1/startIndex');
@@ -128,23 +131,27 @@
define('ANALYZER_NOSTOPEN', 'http://schemas.talis.com/2007/bigfoot/analyzers#nostop-en');
define('ANALYZER_NORMEN', 'http://schemas.talis.com/2007/bigfoot/analyzers#norm-en');
+define('OWL_ANNOTATIONPROPERTY', 'http://www.w3.org/2002/07/owl#AnnotationProperty');
define('OWL_CLASS', 'http://www.w3.org/2002/07/owl#Class');
define('OWL_COMPLEMENTOF', 'http://www.w3.org/2002/07/owl#complementOf');
+define('OWL_DATATYPEPROPERTY', 'http://www.w3.org/2002/07/owl#DatatypeProperty');
+define('OWL_DISJOINTWITH', 'http://www.w3.org/2002/07/owl#disjointWith');
define('OWL_EQUIVALENTCLASS', 'http://www.w3.org/2002/07/owl#equivalentClass');
define('OWL_EQUIVALENTPROPERTY', 'http://www.w3.org/2002/07/owl#equivalentProperty');
-define('OWL_SAMEAS', 'http://www.w3.org/2002/07/owl#sameAs');
-define('OWL_INVERSEOF', 'http://www.w3.org/2002/07/owl#inverseOf');
-define('OWL_INVERSEFUNCTIONALPROPERTY', 'http://www.w3.org/2002/07/owl#InverseFunctionalProperty');
define('OWL_FUNCTIONALPROPERTY', 'http://www.w3.org/2002/07/owl#FunctionalProperty');
+define('OWL_INVERSEFUNCTIONALPROPERTY', 'http://www.w3.org/2002/07/owl#InverseFunctionalProperty');
+define('OWL_INVERSEOF', 'http://www.w3.org/2002/07/owl#inverseOf');
define('OWL_OBJECTPROPERTY', 'http://www.w3.org/2002/07/owl#ObjectProperty');
-define('OWL_DATATYPEPROPERTY', 'http://www.w3.org/2002/07/owl#DatatypeProperty');
-define('OWL_TRANSITIVEPROPERTY', 'http://www.w3.org/2002/07/owl#TransitiveProperty');
+define('OWL_ONTOLOGY', 'http://www.w3.org/2002/07/owl#Ontology');
+define('OWL_SAMEAS', 'http://www.w3.org/2002/07/owl#sameAs');
define('OWL_SYMMETRICPROPERTY', 'http://www.w3.org/2002/07/owl#SymmetricProperty');
-define('OWL_ANNOTATIONPROPERTY', 'http://www.w3.org/2002/07/owl#AnnotationProperty');
-define('OWL_DISJOINTWITH', 'http://www.w3.org/2002/07/owl#disjointWith');
+define('OWL_TRANSITIVEPROPERTY', 'http://www.w3.org/2002/07/owl#TransitiveProperty');
define('OPEN_LASTCACHEDPAGE', 'http://open.vocab.org/terms/lastCachedPage');
define('OPEN_JSON', 'http://open.vocab.org/terms/json');
+define('VANN_PREFERRED_NAMESPACE_PREFIX', 'http://purl.org/vocab/vann/preferredNamespacePrefix');
+define('VANN_PREFERRED_NAMESPACE_URI', 'http://purl.org/vocab/vann/preferredNamespaceUri');
+
define('OUTPUT_TYPE_RDF', 'rdf');
define('OUTPUT_TYPE_XML', 'xml');
define('OUTPUT_TYPE_TURTLE', 'turtle');
=======================================
--- /trunk/simplegraph.class.php Thu Dec 1 14:40:47 2011
+++ /trunk/simplegraph.class.php Thu Jan 12 01:59:37 2012
@@ -370,55 +370,29 @@
/**
* Fetch the first literal value for a given subject and predicate. If
there are multiple possible values then one is selected at random.
* @param string s the subject to search for
- * @param string p the predicate to search for, or an array of predicates
+ * @param string/array properties the predicate(s) to search for
* @param string default a default value to use if no literal values are
found
+ * @param string/array languages an ordered array of language preferences
* @return string the first literal value found or the supplied default
if no values were found
*/
- function get_first_literal($s, $p, $default = null, $preferred_language
= null) {
-
- $best_literal = $default;
- if ( array_key_exists($s, $this->_index)) {
- if (is_array($p)) {
- foreach($p as $p_uri) {
- if(array_key_exists($p_uri, $this->_index[$s]) ) {
- foreach ($this->_index[$s][$p_uri] as $value) {
- if ($value['type'] == 'literal') {
- if ($preferred_language == null) {
- return $value['value'];
- }
- else {
- if (array_key_exists('lang', $value) && $value['lang']
== $preferred_language) {
- return $value['value'];
- }
- else {
- $best_literal = $value['value'];
- }
- }
- }
- }
- }
- }
- }
- else if(array_key_exists($p, $this->_index[$s]) ) {
- foreach ($this->_index[$s][$p] as $value) {
- if ($value['type'] == 'literal') {
- if ($preferred_language == null) {
+ function get_first_literal($s, $properties, $default = null, $languages
= array('') ) {
+ if (!$this->has_triples_about($s)) { return $default; }
+ if (!is_array($properties)) { $properties = array($properties); }
+ if (!is_array($languages)) { $languages = array($languages); }
+ foreach($languages as $language) {
+ foreach($properties as $property) {
+ if($this->subject_has_property($s, $property)) {
+ $values = $this->get_subject_property_values($s, $property);
+ foreach ($values as $value) {
+ if ($value['type'] != 'literal') { continue; }
+ if ( (isset($value['lang']) && strtolower($value['lang']) ==
strtolower($language)) || empty($language) ) {
return $value['value'];
}
- else {
- if (array_key_exists('lang', $value) && $value['lang'] ==
$preferred_language) {
- return $value['value'];
- }
- else {
- $best_literal = $value['value'];
- }
- }
}
}
}
}
-
- return $best_literal;
+ return $default;
}
/**
=======================================
--- /trunk/tests/simplegraph.test.php Wed Jan 11 03:59:48 2012
+++ /trunk/tests/simplegraph.test.php Thu Jan 12 01:59:37 2012
@@ -133,6 +133,7 @@
$this->assertEquals( "literal",
$g->get_first_literal('http://example.org/subj', 'http://example.org/pred'));
}
+
function test_get_first_literal_ignores_resources() {
$g = new SimpleGraph();
$g->add_resource_triple('http://example.org/subj', 'http://example.org/pred', 'http://example.org/obj');