Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to merge graphs? #402

Open
lecoqlibre opened this issue Jul 24, 2023 · 1 comment
Open

Is there a way to merge graphs? #402

lecoqlibre opened this issue Jul 24, 2023 · 1 comment

Comments

@lecoqlibre
Copy link

How to merge two RDF graphs in a single one?

@zozlak
Copy link
Collaborator

zozlak commented Jul 24, 2023

As far as I know it can not be done in a really convenient way.
Two quick methods coming to my mind:

  • Serialize both graphs as n-triples, concatenate output strings and parse again.
  • foreach ($graph1->resources() as $res1) {
      $res2 = $graph2->resource($res1->getUri());
      foreach ($res->propertyUris() as $prop) {
        foreach ($res->all($prop) as $value) {
          $res2->add($prop, $value);
        }
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants