Unable to see the relationship in mongo to graph mapping

Hi Team,

I'm trying to create a stardog mapping syntax (SMS) to virtual graph from mongo data source.

For the below data and mapping i couldn't see any relationship "productionCompany" which is in the array format in the mongo db.

Could somebody please advise if anything needs to be corrected or any points needs to be considerd ?

as i'm following the base instructions from Bring More Structure to MongoDB With a Knowledge Graph | Stardog and Mapping Data Sources | Stardog Documentation 7.7.2 for different dataset

References:
Output:


Sample Mongo Data:

{
  "_id": ObjectId("6135b2a3885ba5ff8c3d0df9"),
  "genres": "[{'id': 18, 'name': 'Drama'}]",
  "id": 16420,
  "imdb_id": "tt0114057",
  "original_language": "en",
  "original_title": "Othello",
  "overview": "The evil Iago pretends to be friend of Othello in order to manipulate him to serve his own end in the film version of this Shakespeare classic.",
  "popularity": 1.845899,
  "production_companies": "[{'name': 'Columbia Pictures', 'id': 5}, {'name': 'Castle Rock Entertainment', 'id': 97}]",
  "production_countries": "[{'iso_3166_1': 'IT', 'name': 'Italy'}]",
  "release_date": "15-12-1995",
  "revenue": 0,
  "runtime": 123,
  "status": "Released",
  "tagline": "Envy, greed, jealousy and love.",
  "title": "Othello",
  "vote_average": 7,
  "vote_count": 33
}

Mapping:

PREFIX : <http://ac.com/movies/>
MAPPING <urn:movies>
FROM JSON {
  "movies":{
    "id":"?movieId",
    "imdb_id":"?imdbId",
    "original_language":"?lang",
    "original_title":"?title",
    "overview":"?overView",
    "popularity":"?popularity",
    "productionCompany":[ {
      "name":"?productionCompanyName",
      "id":"?productionCompanyId"
    } ],
    "release_date":"?releaseDate",
    "revenue":"?revenue",
    "runtime":"?time",
    "status":"?status",
    "tagline":"?movieTagline",
    "title":"?movieTitle",
    "vote_average":"?voteavg",
    "vote_count":"?voteCount"
  }
}
TO {
  ?movies a :Movie ;
    :movieid ?movieId;
    :imdb_id ?imdbId;
    :origlanguage ?lang;
    :origtitle ?title;
    :overview ?overView;
    :popularity ?popularity;
    :daterelease ?releaseDate;
    :revenuecost ?revenue;
    :runningtime ?time;
    :moviestatus ?status;
    :movietagline ?movieTagline;
    :movietitle ?movieTitle;
    :avgvote ?voteavg;
    :votecount ?voteCount ;
    :productionCompany ?productionCompany .

  ?productionCompany a :Org ;
                     :name ?productionCompanyName ;
                     :id ?productionCompanyId .
  
}
WHERE {
  BIND (template("http://ac.com/movies/{productionCompanyId}") AS ?productionCompany)
  BIND (xsd:string(?movieId) AS ?movies)
}

NOTE: with below kind of mapping i can get results in an embeeded json way. but i need to assign only "Id" as object for relationship "productioncompanies"


result:

Hey Muthu,

It looks like your "production_companies" value in the MongoDB document is a string, not a JSON object. Is this the case? Here is the fragment I'm talking about:

  "production_companies": "[{'name': 'Columbia Pictures', 'id': 5}, {'name': 'Castle Rock Entertainment', 'id': 97}]",

If it were an array with objects, I would expect to see it without quotes, eg:

  "production_companies": [{'name': 'Columbia Pictures', 'id': 5}, {'name': 'Castle Rock Entertainment', 'id': 97}],

Stardog will not be able to do anything special if it's a string. I would suggest you transform the document in MongoDB to contain the structure as part of the document and not encoded as a string.

Additionally, you have not specified the same key name in the top-level document. The example data uses the key production_companies but the mapping uses productionCompany.

Hope this helps.

Jess

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.