[Mulgara-svn] r286 - in trunk/src/jar: content-n3/java/org/mulgara/content/n3 resolver-spi/java/org/mulgara/resolver/spi
pag at mulgara.org
pag at mulgara.org
Fri Jun 22 20:27:44 UTC 2007
Author: pag
Date: 2007-06-22 15:27:43 -0500 (Fri, 22 Jun 2007)
New Revision: 286
Modified:
trunk/src/jar/content-n3/java/org/mulgara/content/n3/Parser.java
trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java
Log:
updated Localizing to only create temporary files when needed. Plus let the N3 parser load _:node### blank nodes by number and not by string
Modified: trunk/src/jar/content-n3/java/org/mulgara/content/n3/Parser.java
===================================================================
--- trunk/src/jar/content-n3/java/org/mulgara/content/n3/Parser.java 2007-06-21 20:53:02 UTC (rev 285)
+++ trunk/src/jar/content-n3/java/org/mulgara/content/n3/Parser.java 2007-06-22 20:27:43 UTC (rev 286)
@@ -88,6 +88,8 @@
private static final Logger logger = Logger.getLogger(Parser.class.getName());
private static final String ANON_TAG = "_:";
+
+ private static final String LOCAL_ANON_TAG = ANON_TAG + "node";
/**
* Maximum size that the {@link #triples} buffer can attain without the
@@ -528,9 +530,9 @@
* @return The number part of the node.
*/
private long parseAnonId(AST node) {
- // TODO: This is wrong. There may be more text after the _:
try {
- return Long.parseLong(node.toString().substring(ANON_TAG.length()));
+ int startPoint = node.toString().startsWith(LOCAL_ANON_TAG) ? LOCAL_ANON_TAG.length() : ANON_TAG.length();
+ return Long.parseLong(node.toString().substring(startPoint));
} catch (NumberFormatException nfe) {
return -1;
}
Modified: trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java
===================================================================
--- trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java 2007-06-21 20:53:02 UTC (rev 285)
+++ trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java 2007-06-22 20:27:43 UTC (rev 286)
@@ -89,6 +89,9 @@
/** Mapping between blank node rdf:nodeIDs and local node numbers. */
private StringToLongMap blankNodeNameMap;
+
+ /** Indicates that the maps have been initialized and are no longer null. */
+ private boolean mapsInitialized = false;
/**
* Does the localization need to be done in the persistent store.
@@ -102,7 +105,7 @@
* @throws IllegalArgumentException if <var>globalAnswer</var> is
* <code>null</code>
*/
- public LocalizedTuples(ResolverSession session, Answer globalAnswer, boolean persist) throws TuplesException
+ public LocalizedTuples(ResolverSession session, Answer globalAnswer, boolean persist)
{
if (session == null) {
throw new IllegalArgumentException("Null \"session\" parameter");
@@ -115,13 +118,6 @@
answer = (Answer) globalAnswer.clone();
setVariables(answer.getVariables());
- try {
- blankNodeIdMap = IntFile.open(TempDir.createTempFile("localIdMap", null), true);
- blankNodeNameMap = new StringToLongMap();
- } catch (IOException ioe) {
- throw new TuplesException("Unable to localize tuples", ioe);
- }
-
this.persist = persist;
}
@@ -157,11 +153,13 @@
public void close() throws TuplesException {
answer.close();
- blankNodeNameMap.delete();
- try {
- blankNodeIdMap.delete();
- } catch (IOException ioe) {
- throw new TuplesException("Unable to manage temporary files", ioe);
+ if (mapsInitialized) {
+ blankNodeNameMap.delete();
+ try {
+ blankNodeIdMap.delete();
+ } catch (IOException ioe) {
+ throw new TuplesException("Unable to manage temporary files", ioe);
+ }
}
}
@@ -230,15 +228,21 @@
* @return A gNode ID that is unique and reproducable for the blank node.
* @throws NodePoolException There was an error allocating a new gNode ID.
* @throws LocalizeException There was an error recalling an earlier conversion, or mixed local and remote nodes.
+ * @throws TuplesException There was an error creating the maps needed for this tuples.
* @throws IOException There was an error communicating with files used for recalling conversions.
*/
- private long localizeBlankNode(BlankNode node) throws NodePoolException, LocalizeException, IOException {
+ private long localizeBlankNode(BlankNode node) throws NodePoolException, LocalizeException, TuplesException, IOException {
long nodeId;
if (node instanceof BlankNodeImpl) {
nodeId = ((BlankNodeImpl)node).getNodeId();
if (nodeId < 0) {
long foreignId = -nodeId;
- nodeId = blankNodeIdMap.getLong(foreignId);
+ if (mapsInitialized) {
+ nodeId = blankNodeIdMap.getLong(foreignId);
+ } else {
+ initMaps();
+ nodeId = 0;
+ }
if (nodeId == 0) {
nodeId = newBlankNode();
blankNodeIdMap.putLong(foreignId, nodeId);
@@ -246,7 +250,12 @@
}
} else {
String foreignIdStr = node.toString();
- nodeId = blankNodeNameMap.get(foreignIdStr);
+ if (mapsInitialized) {
+ nodeId = blankNodeNameMap.get(foreignIdStr);
+ } else {
+ initMaps();
+ nodeId = 0;
+ }
if (nodeId == 0) {
nodeId = newBlankNode();
blankNodeNameMap.put(foreignIdStr, nodeId);
@@ -255,4 +264,15 @@
return nodeId;
}
+
+ private void initMaps() throws TuplesException {
+ try {
+ blankNodeIdMap = IntFile.open(TempDir.createTempFile("localIdMap", null), true);
+ blankNodeNameMap = new StringToLongMap();
+ } catch (IOException ioe) {
+ throw new TuplesException("Unable to localize tuples", ioe);
+ }
+ mapsInitialized = true;
+ }
+
}
More information about the Mulgara-svn
mailing list