Skip to content

Instantly share code, notes, and snippets.

@dantman
Last active December 17, 2015 20:09
Show Gist options
  • Select an option

  • Save dantman/5665307 to your computer and use it in GitHub Desktop.

Select an option

Save dantman/5665307 to your computer and use it in GitHub Desktop.
A script to scan over prefix.cc and determine the most popular patterns for rdf namespace IRIs
<?php
$ns = json_decode( file_get_contents( "http://prefix.cc/popular/all.file.json" ) );
foreach ( $ns as $k => $v ) {
if ( is_null( $v ) ) {
unset( $ns->{$k} );
}
}
$types = array( '/ns/', '/ns#', '/rdf/', '/rdf#', '/ns/', '/ns#', '/schema/', '/schema#', '/ontologies/', '/ontologies#', '/vocab/', '/vocab#', '/namespaces/', '/namespaces#', '/ontology/', '/ontology#', '/xml/', '/xml#', '/owl/', '/owl#', '/schema/', '/schema#', '/spec/', '/spec#', '/terms/', '/terms#', '/schemas/', '/schemas#' );
$types = array_combine( $types, array_fill( 0, count( $types ), 0 ) );
foreach ( $ns as $p => $uri ) {
foreach( $types as $str => &$n ) {
if ( strpos( $uri, $str ) !== false ) {
$n++;
}
}
}
arsort( $types, SORT_NUMERIC );
echo "Pattern usage:\n";
foreach ( $types as $str => &$n ) {
echo "$n\t$str\n";
}
echo "\n";
$combined = array();
foreach ( $types as $str => &$n ) {
$short = preg_replace( '![#/]$!', '', $str );
if ( !array_key_exists( $short, $combined ) ) {
$combined[$short] = 0;
}
$combined[$short] += $n;
}
arsort( $combined, SORT_NUMERIC );
echo "Combined:\n";
foreach ( $combined as $str => &$n ) {
echo "$n\t$str\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment