From: Bret C. <bre...@ya...> - 2004-08-27 21:18:56
|
Kal, A belated "thank you" for your help getting queries to parse using source locators. I have used your help to get it working. FYI, I've also attached my own analysis of how I made the mistakes I did & how the documentation might be improved so that people like me (if there are any :>) don't make the same mistakes. (It's probably more information than would be helpful, so you might just skip to part B. Suggestion: Table Describing Different Types of Locator.) Bret --- tm4...@li... wrote: > Message: 1 > Date: Tue, 24 Aug 2004 09:42:31 +0100 > From: kal <ka...@te...> > To: Bret Cohen <bre...@ya...> > CC: tm4j <tm4...@li...> > Subject: [TM4J-users] Re: resend: Problems parsing > tolog queries > > 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... > === message truncated === __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail |