@@ -5173,6 +5173,175 @@ public void ShouldApplyPropertyPath()
51735173 Assert . IsTrue ( string . Equals ( result . Rows [ 1 ] [ "?N" ] , "Donald Duck@EN-US" , StringComparison . Ordinal ) ) ;
51745174 }
51755175
5176+ [ TestMethod ]
5177+ public void ShouldApplyPropertyPathOverFederationOfLocalDataSourcesOnly ( )
5178+ {
5179+ //The two hops of the path live in two different graphs of the same federation: this must keep working
5180+ //exactly as before, since local members are still merged into one unified adjacency (see FlattenFederation)
5181+ RDFGraph dogOfGraph = new RDFGraph ( [ new RDFTriple ( new RDFResource ( "ex:pluto" ) , new RDFResource ( "ex:dogOf" ) , new RDFResource ( "ex:topolino" ) ) ] ) ;
5182+ RDFGraph hasNameGraph = new RDFGraph ( [ new RDFTriple ( new RDFResource ( "ex:topolino" ) , new RDFResource ( "ex:hasName" ) , new RDFResource ( "ex:topolinoName" ) ) ] ) ;
5183+ RDFFederation federation = new RDFFederation ( ) . AddGraph ( dogOfGraph ) . AddGraph ( hasNameGraph ) ;
5184+
5185+ RDFPropertyPath propertyPath = new RDFPropertyPath ( new RDFVariable ( "?Y" ) , new RDFVariable ( "?N" ) )
5186+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:dogOf" ) ) )
5187+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:hasName" ) ) ) ;
5188+ RDFQueryEngine queryEngine = new RDFQueryEngine ( ) ;
5189+ RDFTable result = queryEngine . ApplyPropertyPath ( propertyPath , federation ) ;
5190+
5191+ Assert . IsNotNull ( result ) ;
5192+ Assert . AreEqual ( 2 , result . ColumnsCount ) ;
5193+ Assert . AreEqual ( 1 , result . RowsCount ) ;
5194+ Assert . IsTrue ( string . Equals ( result . Rows [ 0 ] [ "?Y" ] , "ex:pluto" , StringComparison . Ordinal ) ) ;
5195+ Assert . IsTrue ( string . Equals ( result . Rows [ 0 ] [ "?N" ] , "ex:topolinoName" , StringComparison . Ordinal ) ) ;
5196+ }
5197+
5198+ [ TestMethod ]
5199+ public void ShouldApplyPropertyPathAcrossFederationWithSPARQLEndpointAndMergeResults ( )
5200+ {
5201+ server
5202+ . Given (
5203+ Request . Create ( )
5204+ . WithPath ( "/RDFQueryEngineTest/ShouldApplyPropertyPathAcrossFederationWithSPARQLEndpointAndMergeResults/sparql" )
5205+ . UsingGet ( )
5206+ . WithParam ( queryParams => queryParams . ContainsKey ( "query" ) ) )
5207+ . RespondWith (
5208+ Response . Create ( )
5209+ . WithBody (
5210+ """
5211+ <?xml version="1.0" encoding="utf-8"?>
5212+ <sparql xmlns="http://www.w3.org/2005/sparql-results#">
5213+ <head>
5214+ <variable name="?Y" />
5215+ <variable name="?N" />
5216+ </head>
5217+ <results>
5218+ <result>
5219+ <binding name="?Y"><uri>ex:fido</uri></binding>
5220+ <binding name="?N"><uri>ex:paperinoName</uri></binding>
5221+ </result>
5222+ </results>
5223+ </sparql>
5224+ """ , encoding : Encoding . UTF8 )
5225+ . WithHeader ( "Content-Type" , "application/sparql-results+xml" )
5226+ . WithStatusCode ( HttpStatusCode . OK ) ) ;
5227+
5228+ //The federation has one local graph (pluto -> topolinoName) and one remote endpoint (fido -> paperinoName,
5229+ //mocked above): both bindings are fully contained in a single source, so both must show up in the merge
5230+ RDFGraph localGraph = new RDFGraph (
5231+ [
5232+ new RDFTriple ( new RDFResource ( "ex:pluto" ) , new RDFResource ( "ex:dogOf" ) , new RDFResource ( "ex:topolino" ) ) ,
5233+ new RDFTriple ( new RDFResource ( "ex:topolino" ) , new RDFResource ( "ex:hasName" ) , new RDFResource ( "ex:topolinoName" ) )
5234+ ] ) ;
5235+ RDFSPARQLEndpoint endpoint = new RDFSPARQLEndpoint ( new Uri ( server . Url + "/RDFQueryEngineTest/ShouldApplyPropertyPathAcrossFederationWithSPARQLEndpointAndMergeResults/sparql" ) ) ;
5236+ RDFFederation federation = new RDFFederation ( ) . AddGraph ( localGraph ) . AddSPARQLEndpoint ( endpoint ) ;
5237+
5238+ RDFPropertyPath propertyPath = new RDFPropertyPath ( new RDFVariable ( "?Y" ) , new RDFVariable ( "?N" ) )
5239+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:dogOf" ) ) )
5240+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:hasName" ) ) ) ;
5241+ RDFQueryEngine queryEngine = new RDFQueryEngine ( ) ;
5242+ RDFTable result = queryEngine . ApplyPropertyPath ( propertyPath , federation ) ;
5243+
5244+ Assert . IsNotNull ( result ) ;
5245+ Assert . AreEqual ( 2 , result . ColumnsCount ) ;
5246+ Assert . AreEqual ( 2 , result . RowsCount ) ;
5247+ Assert . IsTrue ( result . Rows . Any ( row => string . Equals ( row [ "?Y" ] , "ex:pluto" , StringComparison . Ordinal ) && string . Equals ( row [ "?N" ] , "ex:topolinoName" , StringComparison . Ordinal ) ) ) ;
5248+ Assert . IsTrue ( result . Rows . Any ( row => string . Equals ( row [ "?Y" ] , "ex:fido" , StringComparison . Ordinal ) && string . Equals ( row [ "?N" ] , "ex:paperinoName" , StringComparison . Ordinal ) ) ) ;
5249+ }
5250+
5251+ [ TestMethod ]
5252+ public void ShouldApplyPropertyPathAcrossNestedFederationReachingSPARQLEndpointAtDepth2 ( )
5253+ {
5254+ server
5255+ . Given (
5256+ Request . Create ( )
5257+ . WithPath ( "/RDFQueryEngineTest/ShouldApplyPropertyPathAcrossNestedFederationReachingSPARQLEndpointAtDepth2/sparql" )
5258+ . UsingGet ( )
5259+ . WithParam ( queryParams => queryParams . ContainsKey ( "query" ) ) )
5260+ . RespondWith (
5261+ Response . Create ( )
5262+ . WithBody (
5263+ """
5264+ <?xml version="1.0" encoding="utf-8"?>
5265+ <sparql xmlns="http://www.w3.org/2005/sparql-results#">
5266+ <head>
5267+ <variable name="?Y" />
5268+ <variable name="?N" />
5269+ </head>
5270+ <results>
5271+ <result>
5272+ <binding name="?Y"><uri>ex:fido</uri></binding>
5273+ <binding name="?N"><uri>ex:paperinoName</uri></binding>
5274+ </result>
5275+ </results>
5276+ </sparql>
5277+ """ , encoding : Encoding . UTF8 )
5278+ . WithHeader ( "Content-Type" , "application/sparql-results+xml" )
5279+ . WithStatusCode ( HttpStatusCode . OK ) ) ;
5280+
5281+ //The endpoint sits two levels deep (outerFederation -> innerFederation -> endpoint): FlattenFederation
5282+ //must recurse through the nesting to reach it, exactly as GetAllNodes/CollectPropertyEdges already do for
5283+ //Graph/Store members
5284+ RDFSPARQLEndpoint endpoint = new RDFSPARQLEndpoint ( new Uri ( server . Url + "/RDFQueryEngineTest/ShouldApplyPropertyPathAcrossNestedFederationReachingSPARQLEndpointAtDepth2/sparql" ) ) ;
5285+ RDFFederation innerFederation = new RDFFederation ( ) . AddSPARQLEndpoint ( endpoint ) ;
5286+ RDFFederation outerFederation = new RDFFederation ( ) . AddFederation ( innerFederation ) ;
5287+
5288+ RDFPropertyPath propertyPath = new RDFPropertyPath ( new RDFVariable ( "?Y" ) , new RDFVariable ( "?N" ) )
5289+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:dogOf" ) ) )
5290+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:hasName" ) ) ) ;
5291+ RDFQueryEngine queryEngine = new RDFQueryEngine ( ) ;
5292+ RDFTable result = queryEngine . ApplyPropertyPath ( propertyPath , outerFederation ) ;
5293+
5294+ Assert . IsNotNull ( result ) ;
5295+ Assert . AreEqual ( 2 , result . ColumnsCount ) ;
5296+ Assert . AreEqual ( 1 , result . RowsCount ) ;
5297+ Assert . IsTrue ( string . Equals ( result . Rows [ 0 ] [ "?Y" ] , "ex:fido" , StringComparison . Ordinal ) ) ;
5298+ Assert . IsTrue ( string . Equals ( result . Rows [ 0 ] [ "?N" ] , "ex:paperinoName" , StringComparison . Ordinal ) ) ;
5299+ }
5300+
5301+ [ TestMethod ]
5302+ public void ShouldNotReconstructPropertyPathHopThatCrossesFromSPARQLEndpointToLocalDataSource ( )
5303+ {
5304+ //The endpoint only knows the first hop (dogOf) and has no hasName data of its own, so its own SPARQL
5305+ //engine correctly finds no match for the full 2-hop path and returns an empty result set
5306+ server
5307+ . Given (
5308+ Request . Create ( )
5309+ . WithPath ( "/RDFQueryEngineTest/ShouldNotReconstructPropertyPathHopThatCrossesFromSPARQLEndpointToLocalDataSource/sparql" )
5310+ . UsingGet ( )
5311+ . WithParam ( queryParams => queryParams . ContainsKey ( "query" ) ) )
5312+ . RespondWith (
5313+ Response . Create ( )
5314+ . WithBody (
5315+ """
5316+ <?xml version="1.0" encoding="utf-8"?>
5317+ <sparql xmlns="http://www.w3.org/2005/sparql-results#">
5318+ <head>
5319+ <variable name="?Y" />
5320+ <variable name="?N" />
5321+ </head>
5322+ <results />
5323+ </sparql>
5324+ """ , encoding : Encoding . UTF8 )
5325+ . WithHeader ( "Content-Type" , "application/sparql-results+xml" )
5326+ . WithStatusCode ( HttpStatusCode . OK ) ) ;
5327+
5328+ //The local graph only knows the second hop (hasName) and has no dogOf data of its own, so it also cannot
5329+ //complete the path alone. The (pluto -> topolinoName) binding only exists by stitching the endpoint's
5330+ //dogOf edge with the local graph's hasName edge, which this design does NOT attempt across sources.
5331+ RDFGraph localGraph = new RDFGraph ( [ new RDFTriple ( new RDFResource ( "ex:topolino" ) , new RDFResource ( "ex:hasName" ) , new RDFResource ( "ex:topolinoName" ) ) ] ) ;
5332+ RDFSPARQLEndpoint endpoint = new RDFSPARQLEndpoint ( new Uri ( server . Url + "/RDFQueryEngineTest/ShouldNotReconstructPropertyPathHopThatCrossesFromSPARQLEndpointToLocalDataSource/sparql" ) ) ;
5333+ RDFFederation federation = new RDFFederation ( ) . AddGraph ( localGraph ) . AddSPARQLEndpoint ( endpoint ) ;
5334+
5335+ RDFPropertyPath propertyPath = new RDFPropertyPath ( new RDFVariable ( "?Y" ) , new RDFVariable ( "?N" ) )
5336+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:dogOf" ) ) )
5337+ . AddStep ( RDFPropertyPathStep . Link ( new RDFResource ( "ex:hasName" ) ) ) ;
5338+ RDFQueryEngine queryEngine = new RDFQueryEngine ( ) ;
5339+ RDFTable result = queryEngine . ApplyPropertyPath ( propertyPath , federation ) ;
5340+
5341+ Assert . IsNotNull ( result ) ;
5342+ Assert . AreEqual ( 0 , result . RowsCount ) ;
5343+ }
5344+
51765345 #endregion
51775346
51785347 #region Operator tree tests (Union/Minus)
0 commit comments