These are chat archives for read-write-web/chat

10th
Dec 2015
mo-seph
@mo-seph
Dec 10 2015 18:12
@bblfish it feels like there's a tension between your use of implicit args and the banana-rdf use of Modules which can be imported. I'd be tempted to refactor some of rww along their lines if that makes sense to you.
As an example, the tests work by importing ldp.TestSetup._, then having a class which extends the test suite, supplying implicits from there.
mo-seph
@mo-seph
Dec 10 2015 18:19
so
import ldp.TestSetup._
class RdfWebLocalTest
  extends WebClientLocalTestSuite[Rdf](baseUri, dir)(
  ops,recordBinder,sparqlOps,sparqlGraph,turtleWriter,turtleReader
)

class WebClientLocalTestSuite[Rdf <: RDF](
  baseUri: Rdf#URI,
  dir: Path
)(implicit
  val ops: RDFOps[Rdf],
  val recordBinder: RecordBinder[Rdf],
  sparqlOps: SparqlOps[Rdf],
  sparqlGraph: SparqlEngine[Rdf, Try, Rdf#Graph], // with SparqlUpdate[Rdf, Try, Rdf#Graph],
  turtleWriter: RDFWriter[Rdf, Try, Turtle],
  reader: RDFReader[Rdf, Try, Turtle]
) extends WordSpec with Matchers with TestHelper with TestGraphs[Rdf] {

would become:

class RdfWebLocalTest extends WebClientLocalTestSuite[Rdf](baseUri, dir) 
  with SesameTestSetupModule

class WebClientLocalTestSuite[Rdf <: RDF](
  baseUri: Rdf#URI,
  dir: Path
) extends WordSpec with Matchers with TestHelper with TestGraphs[Rdf] with SetupModule {

trait SetupModule[Rdf] extends RdfModule with RecordBinderModule with SparqlOpsModule with ... {
    //extra test setup things
}

trait SesameTestSetupModule extends SetupModule[Sesame] with SesameModule {
    //extra test setup things
}

(or something similar)

At the moment, it feels like I'm really fighting the type system between two different ways of doing things.
mo-seph
@mo-seph
Dec 10 2015 18:26
And one other question. I'm loving the Free monad, but I haven't quite internalised it yet. Is there a good way to compose recursive and/or conditional operations? I wanted to put together a function to ensure an empty container at a defined URL on an unknown server (which is maybe not very LDP-ish, but useful for tests). I've come up with the following, but I feel that if I was better at Free, there's something more elegant which could be done:
 def ensure_empty_container(parent:Rdf#URI,container:String) = {
    rwwAgent.execute ( askLDPR(appendSegment(parent,container),container_ask, Map() )) map { 
      case true => delete_children(appendSegment(parent,container))
      case false => rwwAgent.execute ( createContainer(parent, Some(container), Graph.empty ) )
    }
  }

  def delete_container(path:Rdf#URI) : Unit = {
    delete_children(path)
    rwwAgent.execute( deleteResource(path))
  }

  def delete_children(path:Rdf#URI) : Unit = {
    for( children <- get_child_containers(path); child <- children ) { 
      delete_container(child) }
    for( children <- get_child_resources(path); child <- children )
      rwwAgent.execute( deleteResource(URI(child.toString)))
  }

  val is_a = URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
  val rdf_res = URI("http://www.w3.org/ns/ldp#Resource")
  val rdf_cont = URI("http://www.w3.org/ns/ldp#Container")

  def get_child_resources(path:Rdf#URI) = rwwAgent.execute(getLDPR(path)) map {
      getSubjects(_,is_a,rdf_res).toSeq collect {case a:Rdf#URI => a}  }

  def get_child_containers(path:Rdf#URI) = rwwAgent.execute(getLDPR(path)) map {
      getSubjects(_,is_a,rdf_cont).toSeq collect {case a:Rdf#URI => a}  }
Henry Story
@bblfish
Dec 10 2015 18:27
hi. Let me catch up with the above.
mo-seph
@mo-seph
Dec 10 2015 18:31
No hurry - about to knock off for the night, and limited time tomorrow
Henry Story
@bblfish
Dec 10 2015 18:32
ok, you're suggestions are probably good. I did not spend a lot of time thinking about that. Was just trying to get it to work. I'll get back to you here... :-)
mo-seph
@mo-seph
Dec 10 2015 18:33
It took me so much head scratching to get banana-rdf's way of doing things. Now, I think it's great and that the whole world should be that way ;)
Henry Story
@bblfish
Dec 10 2015 18:33
Mhh I think the module stuff comes from before banana moved to modules. I did not pick that up in rww-play. So yes, looks like a good idea.
Henry Story
@bblfish
Dec 10 2015 18:44
if I remember correctly the currently the free monad is not so much a free monad as a free functor.
mo-seph
@mo-seph
Dec 10 2015 18:47
Ah, ok.
But it should be possible to upgrade that to a Monad
yep, you need flatMap for conditional operations
So that's an interesting thing to investigate.
the thing I do wonder about is what happens when the actors are on different machines, and they have to cross the tcp layer. Then you may find that one has to be careful about serialisation of the functions...
mo-seph
@mo-seph
Dec 10 2015 18:49

loving the

agent.execute {
  for {
     x <- op1
     y <- op2

way of doing things, btw.

Henry Story
@bblfish
Dec 10 2015 18:50
yep Alex came up with that. But he never really discussed it much ( he was in the US and me in Europe, and when he is not sitting next to you it's difficult to get feedback )
btw, on java with multithreading one can go a very long way with this, without encoountering problems of serialisation. And I am actually not sure what those problems would be.
if this feels like a good idea longer term, one may want to improve the message passing code, so that if an actor has access to the data it can do a few loops on a free monad
Henry Story
@bblfish
Dec 10 2015 18:56
yep you'd need flatMap here I think:
rwwAgent.execute ( askLDPR(appendSegment(parent,container),container_ask, Map() )) flatMap { 
      case true => delete_children(appendSegment(parent,container))
      case false => rwwAgent.execute ( createContainer(parent, Some(container), Graph.empty ) )
    }
mo-seph
@mo-seph
Dec 10 2015 18:58
BTW - still haven't got the above delete code to work, so don't pay too much attn to specifics.
But, yeah, flatMap's what I want there, thanks
Henry Story
@bblfish
Dec 10 2015 18:59
( but as far as serialisations of functions there has been work done on that in Scala land, so we should ask those folks at some point. I think at least understanding how far one gets with a free Monad, would help in the conversation. )
But good that you found a use case for the flatMap :-)
Henry Story
@bblfish
Dec 10 2015 19:08
I suppose there is a little question: how come we are doing for loops when we just have a functor...
mo-seph
@mo-seph
Dec 10 2015 19:26
Running into a more basic issue right now - graphs are coming back with the wrong URIs in. I'm probably missing something, but with curl, I get:
curl -v -H"Content-Type: text/turtle" -X GET http://localhost:8087/test/scaldp_tests
[...]
<>
    a <http://www.w3.org/ns/ldp#BasicContainer>, <http://www.w3.org/ns/ldp#Container>, <http://www.w3.org/ns/posix/stat#Directory> ;
    <http://www.w3.org/ns/ldp#contains> <test_dir/>, <test_graph> ;
[..]
<test_dir/>
    a <http://www.w3.org/ns/ldp#BasicContainer>, <http://www.w3.org/ns/ldp#Container> ;
 [...]
<test_graph>
    a <http://www.w3.org/ns/ldp#Resource> ;
 [...]
Henry Story
@bblfish
Dec 10 2015 19:27
yes, they are relative URLs
we actually need this in banana banana-rdf/banana-rdf#41
mo-seph
@mo-seph
Dec 10 2015 19:28
When this comes back from the WSWebClient, I get
Found triples:
    (http://localhost:8087/test/scaldp_tests, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/ns/ldp#BasicContainer) [null]
[...]
    (http://localhost:8087/test/test_dir/, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/ns/ldp#Container) [null]
[...]
Henry Story
@bblfish
Dec 10 2015 19:29
yes, you client fetches a resource from a particular location, and so transforms the URLs to full ones
mo-seph
@mo-seph
Dec 10 2015 19:29
And I can't quite figure out why - is it prepending the base URL of the server instead of the one from the request?
Note - in the above, the correct URL for the second line is http://localhost:8087/test/scaldp_test/test_dir
So it's transformed it to a full URL based on something other than the URL of the document
Henry Story
@bblfish
Dec 10 2015 19:31
it should be the url of the document
mhh
that looks like a bug
it's one of those bugs that comes up because we have not got relative urls in banana-rdf as per banana-rdf/banana-rdf#41
it would be a lot easier to find those it we had the right typing.
ah no wait
if you check the URI specification.
if you put a / ad the end of http://localhost:8087/test/scaldp_tests then you'll get what you want.
mo-seph
@mo-seph
Dec 10 2015 19:36
ah - I figured it was probably something silly I was doing
thanks! OK, gotta go