function process_row($file, $collection, $writer, $count)
{
    $fileArray = explode('/', $file);
    $id = str_replace('.xml', '', $fileArray[count($fileArray) - 1]);
    $dom = new DOMDocument('1.0', 'UTF-8');
    if ($dom->load($file) === FALSE) {
        echo "{$file} failed to load.\n";
    } else {
        $xpath = new DOMXpath($dom);
        $xpath->registerNamespace("lido", "http://www.lido-schema.org");
        //look for the URI
        $terms = $xpath->query("descendant::lido:term[@lido:label='typereference']");
        $hoardURI = null;
        $typeURI = null;
        foreach ($terms as $term) {
            if (preg_match('/coinhoards\\.org/', $term->nodeValue)) {
                $hoardURI = $term->nodeValue;
                echo "Found {$hoardURI}\n";
            } else {
                //ignore IKMK type references
                $source = $term->getAttribute('lido:source');
                if ($source == 'crro' || $source == 'ocre' || $source == 'pella') {
                    $typeURI = $term->nodeValue;
                }
            }
        }
        //if the type URI can be assertained from the typereference LIDO field
        if (isset($typeURI)) {
            echo "Processing #{$count}: {$id}, {$typeURI}\n";
            generateNumismaticObject($id, $typeURI, $collection, $xpath, $writer);
        } else {
            $typeURI = parseReference($xpath);
            if (isset($typeURI)) {
                echo "Processing #{$count}: {$id}, {$typeURI}\n";
                generateNumismaticObject($id, $typeURI, $collection, $xpath, $writer);
            } else {
                echo "Processing #{$count}: {$id}, unable to match.\n";
            }
        }
    }
}
function parseGT($ast)
{
    assert_ast_type($ast, [NodeType::GT, NodeType::REFERENCE]);
    $type = ast_node_type($ast);
    $data = ast_node_data($ast);
    $source = ast_node_source($ast);
    switch ($type) {
        case NodeType::GT:
            $name = ast_get($data, NodeKey::NAME);
            $t_args = parseTemplateArgs(ast_get($data, NodeKey::TARGS));
            $alias = ast_has($data, NodeKey::ALIAS) ? null : parseIdentifier(ast_get($data, NodeKey::ALIAS));
            return new GT_Spec($source, $name, $t_args, $alias);
            break;
        case NodeType::REFERENCE:
            $info = parseReference($ast);
            grokit_assert($info->isGT(), 'Tried to look up reference as a GT, got a ' . $info->kind() . 'instead ' . $source);
            return $info;
            break;
    }
}