private function sanitizeResource(Resource $res, string $namespace): Resource {
        $nonIdProps = array_diff($res->propertyUris(), array(RC::idProp()));
        if (count($nonIdProps) == 0) {
            // don't do anything when it's purely-id resource
            return $res;
        }

        $this->fedora->fixMetadataReferences($res);

        if ($this->containsWrongRefs($res, $namespace)) {
            echo $res->copy()->getGraph()->serialise('ntriples') . "\n";
            throw new InvalidArgumentException('resource contains references to blank nodes');
        }

        if (count($res->allLiterals(RC::titleProp())) == 0) {
            $res->addLiteral(RC::titleProp(), $res->getResource(RC::idProp()));
        }

        if ($res->isA('http://xmlns.com/foaf/0.1/Person') || $res->isA('http://xmlns.com/foaf/0.1/Agent')) {
            $res = self::makeAgent($res);
        }

        if ($this->resource !== null) {
            $res->addResource(RC::relProp(), $this->resource->getId());
        }

        return $res;
    }