Example #1
0
 /**
  * All of the following names will be encoded to 'Émile Zola': 
  * '%C3%89mile_Zola', '%C3%A9mile_Zola', ' %C3%A9mile Zola ', ' %C3%A9mile _ Zola ', '  Émile _ Zola  '
  * 
  * TODO: maybe we should expect (require) the name to be normalized, e.g. with uppercase
  * first letter and without duplicate spaces or spaces at start or end? 
  * Would make this method much simpler.
  *   
  * @param $name encoded MediaWiki page name, e.g. '%C3%89mile_Zola'.
  * Must not include the namespace (e.g. 'Template:').
  */
 public static function wikiDecode($name)
 {
     PhpUtil::assertString($name, 'name');
     // make first character uppercase
     $name = StringUtil::mb_ucfirst(self::cleanSpace(urldecode($name)));
     return $name;
 }
Example #2
0
 private function updateConfig($dir, $path, $source)
 {
     PhpUtil::assertString($path, 'path');
     PhpUtil::assertString($source, 'source');
     // TODO: add '#1' etc. if necessary on Windows for file names that only differ in case
     // TODO: make suffix configurable
     $file = $dir . $path . '.txt';
     return $this->buildConfigFile($file, $source);
 }
Example #3
0
 public function setDestination($destinationId, $destination)
 {
     PhpUtil::assertString($destinationId, 'destination id');
     PhpUtil::assertType($destination, 'dbpedia\\destinations\\QuadDestination', 'destination');
     if (isset($this->destinations[$destinationId])) {
         throw new \InvalidArgumentException('destination for id [' . $destinationId . '] already set');
     }
     $this->destinations[$destinationId] = $destination;
 }
Example #4
0
 public function addUnit($unit)
 {
     PhpUtil::assertType($unit, 'dbpedia\\ontology\\dataTypes\\UnitDataType', 'unit');
     $unit->setDimension($this);
     foreach ($unit->getLabels() as $label) {
         if (isset($this->units[$label])) {
             throw new \InvalidArgumentException($this . ' already has unit label ' . $label);
         }
         $this->units[$label] = $unit;
     }
 }
Example #5
0
 /**
  * Loads all classes and properties but does not link them.
  *
  * @param $ontology The ontology instance
  * @param $pageNode The page node of the configuration page
  */
 private function createClasses($ontology, $pageNode)
 {
     // PHP keeps going if param type is wrong, but we want an exception
     PhpUtil::assertType($ontology, 'dbpedia\\ontology\\Ontology', 'ontology');
     PhpUtil::assertType($pageNode, 'dbpedia\\wikiparser\\PageNode', 'page node');
     $name = self::getPageName($pageNode);
     foreach ($pageNode->getChildren('TemplateNode') as $node) {
         $templateName = $node->getTitle()->encoded();
         if ($templateName == OntologyClass::TEMPLATE_NAME) {
             $ontClass = new OntologyClass($name);
             $labelProperty = $node->getProperty("rdfs:label");
             if ($labelProperty) {
                 $ontClass->setLabel($labelProperty->getText());
             } else {
                 $this->logger->warn("Class " . $ontClass->getUri() . " does not define any label.");
             }
             $ontology->addClass($ontClass);
         } else {
             if ($templateName == OntologyObjectProperty::TEMPLATE_NAME || $templateName == OntologyDataTypeProperty::TEMPLATE_NAME) {
                 if ($templateName == OntologyObjectProperty::TEMPLATE_NAME) {
                     $ontProperty = new OntologyObjectProperty($name);
                 } else {
                     $ontProperty = new OntologyDataTypeProperty($name);
                 }
                 $labelProperty = $node->getProperty("rdfs:label");
                 if ($labelProperty) {
                     $ontProperty->setLabel($labelProperty->getText());
                 } else {
                     $this->logger->warn("Property without any label found on page " . $pageName);
                 }
                 $typeProperty = $node->getProperty("rdf:type");
                 if ($typeProperty) {
                     if ($typeProperty->getText() == 'owl:FunctionalProperty') {
                         $ontProperty->setFunctional(true);
                     } else {
                         $this->logger->warn("Property with an invalid type found on page " . $pageName);
                     }
                 }
                 $ontology->addProperty($ontProperty);
             }
         }
     }
 }
Example #6
0
 /**
  * @param $baseDir must end with a directory separator (slash or backslash)
  * @param $skipNames names (not paths) of files and directories to skip, e.g. '.svn'. 
  * If not given, all files and directories will be included.
  * @param $paths array of strings, paths of files to use, relative to base dir,
  * using forward slashes. If not given, all files and directories will be included.
  */
 public function __construct($baseDir, $skipNames = null, $paths = null)
 {
     PhpUtil::assertString($baseDir, 'base dir');
     $baseDir = str_replace('\\', '/', realpath($baseDir));
     if (!is_dir($baseDir)) {
         throw new \InvalidArgumentException('base dir must be an existing directory, but is ' . $baseDir);
     }
     // make sure that $baseDir ends with /
     if (!StringUtil::endsWith($baseDir, '/')) {
         $baseDir .= '/';
     }
     if ($skipNames !== null) {
         PhpUtil::assertArray($skipNames, 'skip names');
     } else {
         $skipNames = array();
     }
     if ($paths !== null) {
         PhpUtil::assertArray($paths, 'paths');
     }
     $this->baseDir = $baseDir;
     $this->skipNames = $skipNames;
     $this->paths = $paths;
 }
 public function getDestination($destinationId)
 {
     PhpUtil::assertString($destinationId, 'destination id');
     return $this->destination;
 }
Example #8
0
 /**
  * @param $nsCode namespace code
  * @param $decoded decoded page name. URL-decoded, using normalized spaces (not underscores), first letter uppercase.
  */
 public function __construct($nsCode, $decoded)
 {
     PhpUtil::assertInteger($nsCode, 'namespace code');
     if (!isset(self::$nsNames[$nsCode])) {
         throw new \InvalidArgumentException('unknown namespace code ' . $nsCode);
     }
     PhpUtil::assertString($decoded, 'page name');
     if (strlen($decoded) === 0) {
         throw new WikiParserException('page name must not be empty');
     }
     $this->nsCode = $nsCode;
     $this->nsName = self::$nsNames[$nsCode][0];
     $this->encoded = WikiUtil::wikiEncode($decoded);
     // re-decode to make sure name is normalized
     $this->decoded = WikiUtil::wikiDecode($this->encoded);
 }
Example #9
0
 /**
  * Sets the range of this property.
  *
  * @return string The range of this property.
  */
 public function setRange($range)
 {
     if (!$range instanceof OntologyClass && !$range instanceof DataType) {
         throw new \InvalidArgumentException('range must be an OntologyClass or a DataType, but has type ' . PhpUtil::typeNameOf($range));
     }
     $this->range = $range;
 }
Example #10
0
 public function __construct($file)
 {
     PhpUtil::assertString($file, 'file');
     $this->file = $file;
 }