From: kal <ka...@te...> - 2004-08-24 08:42:01
|
Hi Bret, If you want to query by topic id, use @id instead of the bare id in your query (e.g. @activity). However, your assumption about source locators is not correct. The source locator for a topic is set by calling topic.addSourceLocator(loc), not topic.setSubject(loc). And when the processor resolves a string like 'activity' as a source locator it actually resolves it relative to the baseAddress of the topic map so you would need to do both of these steps: Locator baseLoc = tm.getLocatorFactory().createLocator("URI", "file:///sass.xtm"); tm.setBaseLocator(baseLoc); topic.addSourceLocator(tm.getBaseLocator().resolveRelative("#activity")); The first two lines you only need to do once of course, and then only if you are not reading the topic map in from a file (if you read it in from a file the base address then it should get a baseLocator set automatically). The third line you should do once and only for topics that you create (the ones parsed from the topic map will have a source locator set automatically). Hope this helps! Cheers, Kal Bret Cohen wrote: >This is a resend. The last time I sent this, there >were problems that prevented it from going through > >Kal, > >Once more, a problem, that once more looks like a bug, >but almost surely isn't - yet may be a stimulant to >improve the documentation. I've attached a file >describing my dealings with the problem. > >It has to do with creating a prepared query when the >TopicMap has *not* been read in from an XTM file. I >have no problem when creating & executing prepared >queries on TopicMaps read in from an XTM file. > >Bret > > > > > >_______________________________ >Do you Yahoo!? >Win 1 of 4,000 free domain names from Yahoo! Enter now. >http://promotions.yahoo.com/goldrush > >------------------------------------------------------------------------ > >Tolog Query & Source Indicators > >It appears that Tolog Queries rely on source locators >(rather than, say Topic IDs) >for finding typing topics used within the query. > >This has caused me some problems, and I still haven't >figured out the solution. (I thought I did, but >it doesn't work.) > >Two possible remedies: >1. Can I or you change the parser so that it can > use Topic IDs instead of source locators to locate the typing topic? >2. Can you add documentation on creating Tolog prepared queries > that deals with the source locator problem? > >Here's my story - together with the still unresolved problem: > >I had never worked with source locators, until I came upon this >Exception when I tried to create a prepared query: > >[java] Exception processing all activities query: org.tm4j.tologx.TologParserException: No topic in topic map with source locator SAAS.xtm#activity > >I never had this problem when I was working from a loaded >XTM file, rather than from a TopicMap created from scratch >from memory. > >I then realized that the the readTopicMap() method I had been using >must have added source locators created by appending #topicID >to the name of the XTM file from which the data was loaded - >and that that was why queries run after reading a topic map >from an XTM file were parsing correctly. > >So I figured I could create the same effect for a TopicMap >created from scratch within memory. > >So I used the name of the XTM file to which I want to later >write the TopicMap as my "dummy base locator" for the TopicMap >& then appended #topicID to create my source locators, >mimicing the behavior which the readTopicMap() method >was following. > >Here's an example: >I created a typing topic for a tolog query with ID: "activity" >I added a src locator as follows (exception processing left out) >(Actually, I did this using a createTopic() method, > but the result should be the same): >Topic topic = topicMap.getTopicByID("activity"); >String baseAddress = tm.getBaseLocator().getAddress()+"#"+topic.getID(); >srcLoc = tm.getLocatorFactory().createLocator("URI", baseAddress); >topic.setSubject(srcLoc); > >I then printed the source locator for the activity topic >and the String address obtained from the locato as follows: > >Topic activity = tm.getTopicByID("activity"); >Locator srcLoc = activity.getSubject(); >System.out.println("srcLoc of activity topic: "+srcLoc); > >String srcAddr = srcLoc.getAddress(); >System.out.println("srcAddr of activity topic: "+srcAddr); > >The results indicated that everything went as I had planned... >except for the parsing of the Tolog query, which continued >to give the same error: > >[java] srcLoc of activity topic: org.tm4j.net.memory.URILocatorImpl@dc5bebe1 >[java] srcAddr of activity topic: SAAS.xtm#activity >[java] Exception processing all activities query: org.tm4j.tologx.TologParserException: No topic in topic map with source locator SAAS.xtm#activity > >Since I thought I had just proven that there now exists just that topic, >I don't know why the Tolog parser is still complaining. >(Isn't a source locator just what you get when you use > topic.getSubject().getAddress?) > > |