Example #1
0
/**
 * 
 *
 * @param string $class_id class id
 * @param string $ontology_property_name ontology property name
 * @param string $ontology_property_label ontology property label
 * @param string $range ontology property range
 * @return ontology property id
 */
function createOntologyProperty($class_id, $ontology_property_name, $ontology_property_label, $range)
{
    global $datatype_ranges;
    global $parser_types;
    global $overall_classes;
    if ($ontology_property_name == "") {
        if ($ontology_property_label != "") {
            $ontology_property_name = getCamelCasePropertyNameFromLabel($ontology_property_label);
        } else {
            echo __LINE__ . " This should never happen!";
        }
    }
    if (strpos($range, ",") !== false) {
        die(__LINE__ . ", in range");
    }
    // Object or Datatype Property?
    if (in_array(strtolower($range), $datatype_ranges)) {
        $range_type = "datatype";
        $range = strtolower($range);
    } elseif (in_array(strtolower($range), $parser_types)) {
        $range_type = "datatype";
        // TODO: New Parser Type Rule
        // FIXME FIXME FIXME: $property_name is not defined
        $template_property_parser[$property_name] = strtolower($range);
        if (strtolower($range) == "unit") {
            echo "{$class_id}.{$ontology_property_name} - We can't handle split properties with Units at the moment.";
        }
    } else {
        if ($range == "object") {
            $range = "Thing";
        }
        $range = str_replace(" ", "", $range);
        if (in_array($range, $overall_classes)) {
            $range_type = "object";
        } else {
            echo "[WARNING] Unknown range for {$class_id}.{$ontology_property_name}: {$range}\n";
        }
    }
    // Insert new class property and range into DB
    if (!($ontology_property_id = getOntologyPropertyId($class_id, $ontology_property_name))) {
        if ($range_type == "datatype") {
            $ontology_property_id = createOntologyDatatypePropertyAndGetId($class_id, $ontology_property_name, $range_type, $range, $ontology_property_label);
        } else {
            $ontology_property_id = createOntologyObjectPropertyAndGetId($class_id, $ontology_property_name, $range_type, $range, $ontology_property_label);
        }
    }
    if ($ontology_property_id) {
        if ($range_type == "datatype") {
            // datatype property
            // FIXME FIXME FIXME: $one_property is not defined.
            $query = "INSERT INTO parser_type_rule (class_property_id, parser_type, unit_type) VALUES ('" . $ontology_property_id . "', '" . $template_property_parser[$one_property] . "', NULL)";
            mysqlQuery($query, __LINE__);
        }
    } else {
        die(__LINE__ . " [DIE] error");
    }
    return $ontology_property_id;
}
Example #2
0
                                         }
                                     }
                                 } else {
                                     echo "{$superClass}(.{$superProperty}) ({$class}.{$template_property}) not found \n";
                                 }
                             } elseif ($csvRow[4] != "" && $csvRow[5] != "") {
                                 if (!getOntologyPropertyId($class_id, $superProperty) && $splitted[$template_id][$template_property][getOntologyPropertyId($class_id, getCamelCasePropertyNameFromLabel($csvRow[4]))] == null) {
                                     echo "";
                                     $temp_pid = insertTemplatePropertyAndGetId($template_id, $template_property);
                                     $ontology_property_id = createOntologyProperty($class_id, null, $csvRow[4], $csvRow[5]);
                                     createRelationFromTemplatePropertyToClassProperty($template_id, $temp_pid, $ontology_property_id);
                                     if (getTemplatePropertyId($template_id, $template_property)) {
                                         $splitted[$template_id][$template_property][$ontology_property_id] = true;
                                         //echo ("[SPLIT] on same class: [$class] $csvRow[1] -> [E] $csvRow[4] - [F] $csvRow[5] \n");
                                     }
                                 } elseif (getOntologyPropertyId($class_id, $superProperty) && $splitted[$template_id][$template_property][getOntologyPropertyId($class_id, getCamelCasePropertyNameFromLabel($csvRow[4]))] == null) {
                                     echo "Can't split: {$class}.{$template_property} - {$superProperty} already defined on {$class}, check ranges first\n";
                                 }
                             } else {
                                 $wrong_mappings[] = "{$class}.{$csvRow['1']}\t|\t{$csvRow['4']}\t|\t{$csvRow['5']}";
                             }
                             $current_csv_row = $current_csv_row + 1;
                             $csvRow = $mapping_csv_content[$current_csv_row];
                         }
                     }
                 }
             }
         }
     }
 }
 // Merge properties