$p = '<http://rdf.freebase.com/ns/' . trim(str_replace('/', '.', $parts[1]), '.') . '>';
    $o = $parts[2];
    if (strpos($o, '/m/') !== false) {
        $o = '<http://rdf.freebase.com/ns/m.' . substr($o, 3) . '>';
    } elseif (is_numeric($o)) {
        $o = '"' . $o . '"^^<http://www.w3.org/2001/XMLSchema#gYear>';
    } elseif (preg_match('/^-?\\d+-\\d{2}$/', $o)) {
        $o = '"' . $o . '"^^<http://www.w3.org/2001/XMLSchema#gYearMonth>';
    } elseif (preg_match('/^-?\\d+-\\d{2}-\\d{2}$/', $o)) {
        $o = '"' . $o . '"^^<http://www.w3.org/2001/XMLSchema#date>';
    } else {
        $o = '"' . $o . '"';
    }
    $statement = new Statement($s, $p, $o);
    try {
        foreach ($mapping->mapFreebaseStatement($statement) as $statement) {
            $referencesUrls[$statement->toTSV()] = array_slice($parts, 3);
        }
    } catch (Mappingfailure $e) {
    } catch (Exception $e) {
        echo $e->getMessage() . ': ' . $line . "\n";
    }
    $count++;
    if ($count % 100000 === 0) {
        echo '.';
    }
}
fclose($referencesInput);
//Do mapping
echo "\nMapping\n";
rewind($input);