You are viewing a plain text version of this content. The canonical link for it is here.
Posted to triplesoup-commits@incubator.apache.org by le...@apache.org on 2007/04/13 08:56:16 UTC
svn commit: r528394 [30/35] - in
/incubator/triplesoup/donations/TRIPLES-3-RDFStore: ./ dbms/ dbms/client/
dbms/client/t/ dbms/dbmsproxy/ dbms/deamon/ dbms/doc/ dbms/include/
dbms/libdbms/ dbms/utils/ doc/ include/ lib/ lib/DBD/ lib/RDFStore/
lib/RDFSt...
Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/sflcomp.c
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/sflcomp.c?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/sflcomp.c (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/sflcomp.c Fri Apr 13 01:56:01 2007
@@ -0,0 +1,859 @@
+/* ----------------------------------------------------------------<Prolog>-
+ Name: sflcomp.c
+ Title: Compression functions
+ Package: Standard Function Library (SFL)
+
+ Written: 1991/05/20 iMatix SFL project team <sf...@imatix.com>
+ Revised: 1997/09/08
+
+ Copyright: Copyright (c) 1996-2000 iMatix Corporation
+ License: This is free software; you can redistribute it and/or modify
+ it under the terms of the SFL License Agreement as provided
+ in the file LICENSE.TXT. This software is distributed in
+ the hope that it will be useful, but without any warranty.
+ ------------------------------------------------------------------</Prolog>-*/
+
+#include "sflcomp.h" /* Function prototypes */
+#include <string.h>
+
+
+/* Constants */
+
+#define FLAG_COPY 0x80 /* For LZ/RLE compression */
+#define FLAG_COMPRESS 0x40
+
+
+/* Local function prototypes */
+
+static byte get_match (const byte *source, word ptr, word source_size,
+ short *hash, word *size, short *pos);
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: compress_block
+
+ Synopsis: Takes up to 64Kb of uncompressed data in Source, compresses
+ it using a fast LZ/RLE algorithm and places the result in Dest. The
+ compression technique is comparable to that used by Zip and such tools,
+ but less agressive. It is, however, fast enough to use in realtime.
+ Returns the size of the compressed data. To decompress the data, use
+ the expand_block() function.
+ ---------------------------------------------------------------------[>]-*/
+
+word
+compress_block (
+ const byte *src,
+ byte *dst,
+ word src_size)
+{
+ static short
+ Hash [4096];
+ short SymbolAddress;
+ word Key;
+ word Size;
+ byte Bit = 0;
+ word Command = 0;
+ word src_index = 0;
+ word dst_size = 3;
+ word HeaderIndex = 1;
+
+ dst [0] = FLAG_COMPRESS;
+ for (Key = 0; Key < 4096; Key++)
+ Hash [Key] = -1;
+
+ while ((src_index < src_size) && (dst_size <= src_size))
+ {
+ if (Bit > 15)
+ {
+ dst [HeaderIndex] = (byte) ((Command >> 8) & 0x00ff);
+ dst [HeaderIndex + 1] = (byte) ( Command & 0x00ff);
+ HeaderIndex = dst_size;
+ dst_size += 2;
+ Bit = 0;
+ }
+ for (Size = 1;; Size++)
+ if ((word) (src_index + Size) >= src_size
+ || (src [src_index] != src [src_index + Size])
+ || (Size >= 0x0fff))
+ break;
+
+ if (Size >= 16)
+ {
+ dst [dst_size++] = 0;
+ dst [dst_size++] = (byte) (((word) (Size - 16) >> 8) & 0x00ff);
+ dst [dst_size++] = (byte) ((Size - 16) & 0x00ff);
+ dst [dst_size++] = src [src_index];
+ src_index += Size;
+ Command = (Command << 1) + 1;
+ }
+ else
+ if (get_match (src, src_index, src_size,
+ Hash, &Size, &SymbolAddress) != 0)
+ {
+ Key = ((src_index - SymbolAddress) << 4) + (Size - 3);
+ dst [dst_size++] = (byte) ((Key >> 8) & 0x00ff);
+ dst [dst_size++] = (byte) (Key & 0x00ff);
+ src_index += Size;
+ Command = (Command << 1) + 1;
+ }
+ else
+ {
+ dst [dst_size++] = src [src_index++];
+ Command = (Command << 1);
+ }
+ Bit++;
+ }
+ Command <<= (16 - Bit);
+ dst [HeaderIndex] = (byte) ((Command >> 8) & 0x00ff);
+ dst [HeaderIndex + 1] = (byte) ( Command & 0x00ff);
+
+ if (dst_size > src_size)
+ {
+ for (dst_size = 0; dst_size < src_size; dst_size++)
+ dst [dst_size + 1] = src [dst_size];
+ dst [0] = FLAG_COPY;
+ return (src_size + 1);
+ }
+ return (dst_size);
+}
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: expand_block
+
+ Synopsis: Expands a block of data previously compressed using the
+ compress_block() function. The compressed block is passed in src;
+ the expanded result in dst. dst must be large enough to accomodate
+ the largest possible decompressed block. Returns the size of the
+ uncompressed data.
+ ---------------------------------------------------------------------[>]-*/
+
+word
+expand_block (
+ const byte *src,
+ byte *dst,
+ word src_size)
+{
+ word SymbolAddress;
+ word ChunkSize;
+ word Counter;
+ word Command = 0;
+ word src_index = 1;
+ word dst_size = 0;
+ byte Bit = 0;
+
+ if (src [0] == FLAG_COPY)
+ {
+ for (dst_size = 1; dst_size < src_size; dst_size++)
+ dst [dst_size - 1] = src [dst_size];
+ return (src_size - 1);
+ }
+ while (src_index < src_size)
+ {
+ if (Bit == 0)
+ {
+ Command = src [src_index++] << 8;
+ Command += src [src_index++];
+ Bit = 16;
+ }
+ if (Command & 0x8000)
+ {
+ SymbolAddress = (word) (src [src_index++] << 4);
+ SymbolAddress += (word) (src [src_index] >> 4);
+ if (SymbolAddress)
+ {
+ ChunkSize = (word) (src [src_index++] & 0x0f) + 3;
+ SymbolAddress = dst_size - SymbolAddress;
+ for (Counter = 0; Counter < ChunkSize; Counter++)
+ dst [dst_size++] = dst [SymbolAddress++];
+ }
+ else
+ {
+ ChunkSize = (word) (src [src_index++] << 8);
+ ChunkSize += (word) (src [src_index++] + 16);
+ for (Counter = 0; Counter < ChunkSize; Counter++)
+ dst [dst_size++] = src [src_index];
+ src_index++;
+ }
+ }
+ else
+ dst [dst_size++] = src [src_index++];
+
+ Command <<= 1;
+ Bit--;
+ }
+ return (dst_size);
+}
+
+
+/* -------------------------------------------------------------------------
+ * get_match -- local
+ *
+ * Finds a match for the bytes at the specified offset.
+ */
+
+static byte get_match (const byte *source, word ptr, word source_size,
+ short *hash, word *size, short *pos)
+{
+ word hash_value;
+
+ hash_value = (word) (40543L * (long) ((((source [ptr] << 4) ^
+ source [ptr + 1]) << 4) ^
+ source [ptr + 2]) >> 4) & 0xfff;
+ *pos = hash [hash_value];
+ hash [hash_value] = ptr;
+ if ((word) ((*pos != -1) && ((ptr - *pos)) < 4096U))
+ {
+ for (*size = 0;; (*size)++)
+ if ((*size >= 18)
+ || ((word) (ptr + *size) >= source_size)
+ || (source [ptr + *size] != source [*pos + *size]))
+ break;
+
+ return (byte) (*size >= 3);
+ }
+ return (FALSE);
+}
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: compress_rle
+
+ Synopsis: Takes a block of uncompressed data in src, compresses
+ it using a RLE algorithm and places the result in dst. To decompress
+ the data, use the expand_rle () function. Returns the size of the
+ compressed data. The dst buffer should be 10% larger than the src
+ buffer. The src buffer must be at least src_size + 1 bytes long. It
+ may be modified. The compressed data contains these strings:
+ <Table>
+ [01-7F][data...] String of uncompressed data, 1 to 127 bytes.
+ [83-FF][byte] Run of 3 to 127 identical bytes.
+ [80][len][byte] Run of 128 to 255 identical bytes.
+ [81][lo][hi][byte] Run of 256 to 2^16 identical bytes.
+ [82][len] Run of 3 to 255 spaces.
+ [00][len] Run of 3 to 255 binary zeroes.
+ </Table>
+ ---------------------------------------------------------------------[>]-*/
+
+word
+compress_rle (
+ byte *src,
+ byte *dst,
+ word src_size)
+{
+ word
+ dst_size, /* Size of compressed data */
+ src_scan, /* Scan through source data */
+ run_end, /* Points to end of run of bytes */
+ length = 0; /* Size of the run or string */
+ byte
+ cur_byte, /* Next byte to process */
+ *header; /* Header of unpacked string */
+ Bool
+ have_run; /* TRUE when we have a run */
+
+ src_scan = 0; /* Start at beginning of source */
+ dst_size = 0; /* No output yet */
+ header = NULL; /* No open unpacked string */
+ while (src_scan < src_size)
+ {
+ cur_byte = src [src_scan++];
+ have_run = FALSE; /* Unless we find a run */
+
+ /* Three identical bytes signals the start of a run */
+ if (cur_byte == src [src_scan]
+ && cur_byte == src [src_scan + 1]
+ && (src_scan + 1 < src_size))
+ {
+ /* Stick-in a sentinel character to ensure that the run ends */
+ src [src_size] = !cur_byte;
+ run_end = src_scan; /* src_scan <= src_size */
+ while (src [run_end] == cur_byte)
+ run_end++;
+
+ have_run = TRUE;
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length;
+ header = NULL;
+ }
+ length = run_end - src_scan + 1;
+ src_scan = run_end;
+ }
+ if (have_run)
+ {
+ /* We compress short runs of spaces and nulls separately */
+ if (length < 256 && cur_byte == 0)
+ {
+ dst [dst_size++] = 0x00;
+ dst [dst_size++] = (byte) length;
+ }
+ else
+ if (length < 256 && cur_byte == ' ')
+ {
+ dst [dst_size++] = 0x82;
+ dst [dst_size++] = (byte) length;
+ }
+ else
+ if (length < 128)
+ {
+ dst [dst_size++] = (byte) length | 0x80;
+ dst [dst_size++] = cur_byte;
+ }
+ else
+ if (length < 256) /* Short run 128-255 bytes */
+ {
+ dst [dst_size++] = 0x80;
+ dst [dst_size++] = (byte) length;
+ dst [dst_size++] = cur_byte;
+ }
+ else /* Long run 256-2^16 bytes */
+ {
+ dst [dst_size++] = 0x81;
+ dst [dst_size++] = (byte) (length & 0xff);
+ dst [dst_size++] = (byte) (length >> 8);
+ dst [dst_size++] = cur_byte;
+ }
+ }
+ else
+ {
+ if (!header) /* Start new unpacked string if */
+ { /* necessary */
+ header = &dst [dst_size++];
+ length = 0;
+ }
+ dst [dst_size++] = cur_byte;
+ if (++length == 127) /* Each string can be up to 127 */
+ { /* bytes long (high bit cleared) */
+ *header = (byte) length;
+ header = NULL;
+ }
+ }
+ }
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length;
+ header = NULL;
+ }
+ return (dst_size); /* Return compressed data size */
+}
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: expand_rle
+
+ Synopsis: Expands a block of data previously compressed using the
+ compress_rle() function. The compressed block is passed in src; the
+ expanded result in dst. Dst must be large enough to accomodate the
+ largest possible decompressed block. Returns the size of the expanded
+ data.
+ ---------------------------------------------------------------------[>]-*/
+
+word
+expand_rle (
+ const byte *src,
+ byte *dst,
+ word src_size)
+{
+ word
+ dst_size, /* Size of expanded data */
+ src_scan, /* Scan through source data */
+ length; /* Size of the run or string */
+ byte
+ cur_byte; /* Next byte to process */
+
+ src_scan = 0;
+ dst_size = 0;
+ while (src_scan < src_size)
+ {
+ cur_byte = src [src_scan++];
+
+ /* 1 to 127 is uncompressed string of 1 to 127 bytes */
+ if (cur_byte > 0 && cur_byte < 128)
+ {
+ length = (word) cur_byte;
+ memcpy (dst + dst_size, src + src_scan, length);
+ src_scan += length;
+ dst_size += length;
+ }
+ else /* Run of 3 or more bytes */
+ {
+ switch (cur_byte)
+ {
+ case 0x00: /* Run of 3-255 zeroes */
+ length = src [src_scan++];
+ cur_byte = 0;
+ break;
+ case 0x82: /* Run of 3-255 spaces */
+ length = src [src_scan++];
+ cur_byte = ' ';
+ break;
+ case 0x80: /* Short run 128-255 bytes */
+ length = src [src_scan++];
+ cur_byte = src [src_scan++];
+ break;
+ case 0x81: /* Long run 256-2^16 bytes */
+ length = src [src_scan++];
+ length += src [src_scan++] << 8;
+ cur_byte = src [src_scan++];
+ break;
+ default: /* Run of 3 to 127 bytes */
+ length = cur_byte & 127;
+ cur_byte = src [src_scan++];
+ }
+ memset (dst + dst_size, cur_byte, length);
+ dst_size += length;
+ }
+ }
+ return (dst_size); /* Return expanded data size */
+}
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: compress_nulls
+
+ Synopsis: Similar to compress_rle(), but optimised towards compression
+ of binary zeroes. Use this when you are certain that the sparse areas
+ are set to binary zeroes. You must use expand_nulls () to decompress
+ a block compressed with this function. Returns the size of the
+ compressed data. The dst buffer should be 10% larger than the src
+ buffer. The src buffer must be at least src_size + 1 bytes long. It
+ may be modified. The compressed data contains these strings:
+ <Table>
+ [01-7F][data...] String of uncompressed data, 1 to 127 bytes.
+ [82-FF] Run of 2 to 127 binary zeroes.
+ [81][80-FF] Run of 128 to 255 binary zeroes.
+ [80][lo][hi] Run of 256 to 2^16 binary zeroes.
+ [00][len][byte] Run of 4 to 255 identical bytes.
+ [00][00][lo][hi][byte] Run of 256 to 2^16 identical bytes.
+ </Table>
+ ---------------------------------------------------------------------[>]-*/
+
+word
+compress_nulls (
+ byte *src,
+ byte *dst,
+ word src_size)
+{
+ word
+ dst_size, /* Size of compressed data */
+ src_scan, /* Scan through source data */
+ run_end, /* Points to end of run of bytes */
+ length = 0; /* Size of the run or string */
+ byte
+ cur_byte, /* Next byte to process */
+ *header; /* Header of unpacked string */
+ Bool
+ have_run; /* TRUE when we have a run */
+
+ src_scan = 0; /* Start at beginning of source */
+ dst_size = 0; /* No output yet */
+ header = NULL; /* No open unpacked string */
+ while (src_scan < src_size)
+ {
+ cur_byte = src [src_scan++];
+ have_run = FALSE; /* Unless we find a run */
+
+ /* Two identical bytes may signal the start of a run */
+ if (cur_byte == src [src_scan]
+ && src_scan < src_size)
+ {
+ /* Stick-in a sentinel character to ensure that the run ends */
+ src [src_size] = !cur_byte;
+ run_end = src_scan; /* src_scan <= src_size */
+ while (src [run_end] == cur_byte)
+ run_end++;
+
+ /* A run is 4+ identical bytes or 2+ nulls */
+ if ((run_end - src_scan > 2) || cur_byte == 0)
+ {
+ have_run = TRUE;
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length;
+ header = NULL;
+ }
+ length = run_end - src_scan + 1;
+ src_scan = run_end;
+ }
+ }
+ if (have_run)
+ {
+ if (cur_byte == 0)
+ {
+ if (length < 128) /* 2-127 binary zeroes */
+ dst [dst_size++] = (byte) (length | 0x80);
+ else
+ if (length < 256) /* 128-256 binary zeroes */
+ {
+ dst [dst_size++] = 0x81;
+ dst [dst_size++] = (byte) length;
+ }
+ else /* 256-2^15 binary zeroes */
+ {
+ dst [dst_size++] = 0x80;
+ dst [dst_size++] = (byte) (length & 0xff);
+ dst [dst_size++] = (byte) (length >> 8);
+ }
+ }
+ else
+ if (length < 256) /* Short run 4-255 bytes */
+ {
+ dst [dst_size++] = 0x00;
+ dst [dst_size++] = (byte) length;
+ dst [dst_size++] = cur_byte;
+ }
+ else /* Long run 256-2^16 bytes */
+ {
+ dst [dst_size++] = 0x00;
+ dst [dst_size++] = 0x00;
+ dst [dst_size++] = (byte) (length & 0xff);
+ dst [dst_size++] = (byte) (length >> 8);
+ dst [dst_size++] = cur_byte;
+ }
+ }
+ else
+ {
+ if (!header) /* Start new unpacked string if */
+ { /* necessary */
+ header = &dst [dst_size++];
+ length = 0;
+ }
+ dst [dst_size++] = cur_byte;
+ if (++length == 127) /* Each string can be up to 127 */
+ { /* bytes long (high bit cleared) */
+ *header = (byte) length;
+ header = NULL;
+ }
+ }
+ }
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length;
+ header = NULL;
+ }
+ return (dst_size); /* Return compressed data size */
+}
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: expand_nulls
+
+ Synopsis: Expands a block of data previously compressed using the
+ compress_nulls() function. The compressed block is passed in src; the
+ expanded result in dst. Dst must be large enough to accomodate the
+ largest possible decompressed block. Returns the size of the expanded
+ data.
+ ---------------------------------------------------------------------[>]-*/
+
+word
+expand_nulls (
+ const byte *src,
+ byte *dst,
+ word src_size)
+{
+ word
+ dst_size, /* Size of expanded data */
+ src_scan, /* Scan through source data */
+ length; /* Size of the run or string */
+ byte
+ cur_byte; /* Next byte to process */
+
+ src_scan = 0;
+ dst_size = 0;
+ while (src_scan < src_size)
+ {
+ cur_byte = src [src_scan++];
+
+ /* 1 to 127 is uncompressed string of 1 to 127 bytes */
+ if (cur_byte > 0 && cur_byte < 128)
+ {
+ length = (word) cur_byte;
+ memcpy (dst + dst_size, src + src_scan, length);
+ src_scan += length;
+ dst_size += length;
+ }
+ else /* Run of 2 or more bytes */
+ {
+ switch (cur_byte)
+ {
+ case 0x00: /* Run of non-zero bytes */
+ length = src [src_scan++];
+ if (length == 0) /* Stored as double-byte */
+ {
+ length = src [src_scan++];
+ length += src [src_scan++] << 8;
+ }
+ cur_byte = src [src_scan++];
+ break;
+ case 0x80: /* 256-2^16 zeroes */
+ length = src [src_scan++];
+ length += src [src_scan++] << 8;
+ cur_byte = 0;
+ break;
+ case 0x81: /* 128 to 255 zeroes */
+ length = src [src_scan++];
+ cur_byte = 0;
+ break;
+ default: /* 2 to 127 zeroes */
+ length = cur_byte & 127;
+ cur_byte = 0;
+ }
+ memset (dst + dst_size, cur_byte, length);
+ dst_size += length;
+ }
+ }
+ return (dst_size); /* Return expanded data size */
+}
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: compress_bits
+
+ Synopsis: Similar to compress_rle(), but optimised towards compression
+ of sparse bitmaps. Use this when you are playing with large, sparse
+ bitmaps. You must use expand_bits () to decompress a block compressed
+ with this function. Returns the size of the compressed data. The dst
+ buffer should be 10% larger than the src buffer for worst cases. The
+ src buffer must be at least src_size + 1 bytes long. It may be
+ modified. The compressed data contains these strings:
+ <Table>
+ [00-07] Single byte containing a bit in position 0 to 7.
+ [08-7F][data...] String of uncompressed data, 1 to 120 bytes.
+ [82-FF] Run of 1 to 126 binary zeroes.
+ [81][00-FD] Run of 127 to 380 binary zeroes.
+ [81][FE][len][byte] Run of 4 to 255 identical bytes.
+ [81][FF][lo][hi][byte] Run of 256 to 2^16 identical bytes.
+ [80][lo][hi] Run of 381 to 2^16 binary zeroes.
+ </Table>
+ ---------------------------------------------------------------------[>]-*/
+
+word
+compress_bits (
+ byte *src,
+ byte *dst,
+ word src_size)
+{
+ word
+ dst_size, /* Size of compressed data */
+ src_scan, /* Scan through source data */
+ run_end, /* Points to end of run of bytes */
+ length = 0; /* Size of the run or string */
+ byte
+ cur_byte, /* Next byte to process */
+ *header; /* Header of unpacked string */
+ static byte
+ single_bits [256]; /* Bytes with one bit set */
+ static Bool
+ initialised = FALSE; /* First time flag */
+
+ /* The single_bits table provides a fast lookup for bytes with */
+ /* one bit set. The 'interesting' bytes are non-zero in the table */
+ /* where their value is the output code value (0-7) + 1. */
+ if (!initialised) /* First time? Initialise */
+ {
+ memset (single_bits, 0, 256);
+ single_bits [1] = 1;
+ single_bits [2] = 2;
+ single_bits [4] = 3;
+ single_bits [8] = 4;
+ single_bits [16] = 5;
+ single_bits [32] = 6;
+ single_bits [64] = 7;
+ single_bits [128] = 8;
+ }
+
+ src_scan = 0; /* Start at beginning of source */
+ dst_size = 0; /* No output yet */
+ header = NULL; /* No open unpacked string */
+ while (src_scan < src_size)
+ {
+ cur_byte = src [src_scan++];
+
+ /*- Look for 1 or more binary zeroes, and compress into a run -------*/
+
+ if (cur_byte == 0)
+ {
+ src [src_size] = 0xff; /* Stop with a sentinel */
+ run_end = src_scan; /* src_scan <= src_size */
+ while (src [run_end] == 0)
+ run_end++;
+
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length + 7;
+ header = NULL;
+ }
+ length = run_end - src_scan + 1;
+ src_scan = run_end;
+ if (length < 127) /* 1-126 binary zeroes */
+ dst [dst_size++] = (byte) (++length | 0x80);
+ else
+ if (length < 381) /* 127-380 binary zeroes */
+ {
+ dst [dst_size++] = 0x81;
+ dst [dst_size++] = (byte) length - 127;
+ }
+ else /* 381-2^16 binary zeroes */
+ {
+ dst [dst_size++] = 0x80;
+ dst [dst_size++] = (byte) (length & 0xff);
+ dst [dst_size++] = (byte) (length >> 8);
+ }
+ }
+ else
+
+ /*- Next, look for bytes with 1 bit set; we encode these as 1 byte --*/
+
+ if (single_bits [cur_byte]) /* Single bit value? */
+ {
+ dst [dst_size++] = single_bits [cur_byte] - 1;
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length + 7;
+ header = NULL;
+ }
+ }
+ else
+
+ /*- Next, look for a run of 4 or more identical (non-zero) bytes ----*/
+
+ if (cur_byte == src [src_scan]
+ && cur_byte == src [src_scan + 1]
+ && cur_byte == src [src_scan + 2]
+ && (src_scan < src_size - 2))
+ {
+ src [src_size] = !cur_byte; /* Stick in a sentinel byte */
+ run_end = src_scan; /* src_scan <= src_size */
+ while (src [run_end] == cur_byte)
+ run_end++;
+
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length + 7;
+ header = NULL;
+ }
+ length = run_end - src_scan + 1;
+ src_scan = run_end;
+
+ if (length < 256) /* Short run 4-255 bytes */
+ {
+ dst [dst_size++] = 0x81;
+ dst [dst_size++] = 0xFE;
+ dst [dst_size++] = (byte) length;
+ dst [dst_size++] = cur_byte;
+ }
+ else /* Long run 256-2^16 bytes */
+ {
+ dst [dst_size++] = 0x81;
+ dst [dst_size++] = 0xFF;
+ dst [dst_size++] = (byte) (length & 0xff);
+ dst [dst_size++] = (byte) (length >> 8);
+ dst [dst_size++] = cur_byte;
+ }
+ }
+ else
+
+ /*- Lastly, compress unpackable strings into chunks of 120 bytes ----*/
+
+ {
+ if (!header) /* Start new unpacked string if */
+ { /* necessary */
+ header = &dst [dst_size++];
+ length = 0;
+ }
+ dst [dst_size++] = cur_byte;
+ if (++length == 120) /* Each string can be up to 120 */
+ { /* bytes long (high bit cleared) */
+ *header = (byte) length + 7;
+ header = NULL;
+ }
+ }
+ }
+ if (header) /* If we have a previous unpacked */
+ { /* string, close it */
+ *header = (byte) length + 7;
+ header = NULL;
+ }
+ return (dst_size); /* Return compressed data size */
+}
+
+
+/* ---------------------------------------------------------------------[<]-
+ Function: expand_bits
+
+ Synopsis: Expands a block of data previously compressed using the
+ compress_bits() function. The compressed block is passed in src; the
+ expanded result in dst. Dst must be large enough to accomodate the
+ largest possible decompressed block. Returns the size of the expanded
+ data.
+ ---------------------------------------------------------------------[>]-*/
+
+word
+expand_bits (
+ const byte *src,
+ byte *dst,
+ word src_size)
+{
+ word
+ dst_size, /* Size of expanded data */
+ src_scan, /* Scan through source data */
+ length; /* Size of the run or string */
+ byte
+ cur_byte; /* Next byte to process */
+
+ src_scan = 0;
+ dst_size = 0;
+ while (src_scan < src_size)
+ {
+ cur_byte = src [src_scan++];
+
+ if (cur_byte < 8) /* Single bit in position 0 to 7 */
+ dst [dst_size++] = 1 << cur_byte;
+ else
+ if (cur_byte < 128) /* String of 1 to 120 bytes */
+ {
+ length = (word) cur_byte - 7;
+ memcpy (dst + dst_size, src + src_scan, length);
+ src_scan += length;
+ dst_size += length;
+ }
+ else /* Run of 1 or more bytes */
+ {
+ switch (cur_byte)
+ {
+ case 0x80: /* 381-2^16 binary zeroes */
+ length = src [src_scan++];
+ length += src [src_scan++] << 8;
+ cur_byte = 0;
+ break;
+ case 0x81:
+ length = src [src_scan++];
+ if (length == 0xFE) /* 4-255 non-zero bytes */
+ {
+ length = src [src_scan++];
+ cur_byte = src [src_scan++];
+ }
+ else
+ if (length == 0xFF) /* Run of 256-2^15 non-zero bytes */
+ {
+ length = src [src_scan++];
+ length += src [src_scan++] << 8;
+ cur_byte = src [src_scan++];
+ }
+ else
+ {
+ length += 127;
+ cur_byte = 0; /* 127 to 380 zeroes */
+ }
+ break;
+ default: /* 1 to 126 zeroes */
+ length = (cur_byte - 1) & 127;
+ cur_byte = 0;
+ }
+ memset (dst + dst_size, cur_byte, length);
+ dst_size += length;
+ }
+ }
+ return (dst_size); /* Return expanded data size */
+}
Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/00_utf8.t
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/00_utf8.t?view=auto&rev=528394
==============================================================================
Binary file - no diff available.
Propchange: incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/00_utf8.t
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/01_rdfstore.t
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/01_rdfstore.t?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/01_rdfstore.t (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/01_rdfstore.t Fri Apr 13 01:56:01 2007
@@ -0,0 +1,409 @@
+use strict;
+use Carp;
+
+BEGIN { print "1..300\n"; };
+END { print "not ok 1\n" unless $::loaded; RDFStore::debug_malloc_dump(); eval{ rmtree('cooltest'); }; };
+
+sub ok
+{
+ my $no = shift ;
+ my $result = shift ;
+
+ print "not " unless $result ;
+ print "ok $no\n" ;
+}
+
+sub docat
+{
+ my $file = shift;
+ local $/ = undef;
+ open(CAT,$file) || die "Cannot open $file:$!";
+ my $result = <CAT>;
+ close(CAT);
+ return $result;
+};
+
+use File::Path qw(rmtree);
+
+eval{
+rmtree('cooltest');
+};
+
+use URI;
+use RDFStore;
+use RDFStore::RDFNode;
+use RDFStore::Literal;
+use RDFStore::Resource;
+
+$::loaded = 1;
+print "ok 1\n";
+
+my $tt=2;
+
+# some basic fuzzy tests of the API
+my $imt="ftp://ftp.isi.edu/in-notes/iana/assignments/media_types/";
+ok $tt++, my $foo = new RDFStore::Resource "${imt}text/","html";
+ok $tt++, my $bar = new RDFStore::Resource "${imt}text/html";
+ok $tt++, $foo->equals($bar);
+ok $tt++, my $baz = new RDFStore::Resource ( new URI( "${imt}text/html" ) );
+ok $tt++, $foo->equals($baz);
+ok $tt++, my $buz = new RDFStore::Resource ( "http://xmlhack.com/" );
+ok $tt++, ($buz->getLocalName eq 'http://xmlhack.com/');
+ok $tt++, !($buz->getNamespace);
+ok $tt++, my $biz = new RDFStore::Resource ( "http://xmlhack.com/rss10.php" );
+ok $tt++, ($biz->getLocalName eq 'rss10.php');
+ok $tt++, ($biz->getNamespace eq 'http://xmlhack.com/');
+ok $tt++, my $s=new RDFStore::Resource('http://aaa.com/#test');
+ok $tt++, my $p=new RDFStore::Resource('http://purl.org/dc/elements/1.1/creator');
+ok $tt++, my $o=new RDFStore::Resource('ac');
+ok $tt++, ($o->isa("RDFStore::Resource"));
+ok $tt++, ($o->isa("RDFStore::RDFNode"));
+ok $tt++, ($s->getNamespace eq 'http://aaa.com/#');
+ok $tt++, ($s->getLocalName eq 'test');
+ok $tt++, ($p->getNamespace eq 'http://purl.org/dc/elements/1.1/');
+ok $tt++, ($p->getLocalName eq 'creator');
+ok $tt++, !($o->isbNode);
+ok $tt++, ($o->equals( new RDFStore::Resource('ac') ));
+ok $tt++, my $o1=new RDFStore::Literal( 'this is a test', undef, 'en', 'http://wwww/w/dattype' );
+ok $tt++, ($o1->toString eq 'this is a test');
+ok $tt++, !($o1->getParseType);
+ok $tt++, ($o1->getLang eq 'en');
+ok $tt++, ($o1->getDataType eq 'http://wwww/w/dattype');
+ok $tt++, my $o2=new RDFStore::Literal( 'dddd 1,2,3', 1, 'fff' );
+ok $tt++, ($o2->equals( 'dddd 1,2,3' ) );
+ok $tt++, ($o2->getParseType);
+ok $tt++, ($o2->getLang eq 'fff');
+ok $tt++, ($o2->getDataType eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral');
+ok $tt++, my $st = new RDFStore::Statement( $s, $p, $o );
+ok $tt++, ($st->toString eq '<http://aaa.com/#test> <http://purl.org/dc/elements/1.1/creator> <ac> . ');
+ok $tt++, ($st->isReified == 0);
+ok $tt++, ($st->subject->equals( $s ));
+ok $tt++, ($st->predicate->equals( $p ));
+ok $tt++, ($st->object->equals( $o ));
+ok $tt++, my $st1 = new RDFStore::Statement( $s, $p, $o, undef, 1, new RDFStore::Resource('http://www/A/B/C') );
+ok $tt++, ($st1->isReified == 1);
+ok $tt++, ($st1->subject->equals( $s ));
+ok $tt++, ($st1->predicate->equals( $p ));
+ok $tt++, ($st1->object->equals( $o ));
+ok $tt++, my $n = new RDFStore::Resource('http://www/A/B/C');
+ok $tt++, my $st2 = new RDFStore::Statement( $s, $p, $o2, undef, 1, $n );
+
+ok $tt++, my $rdfstore=new RDFStore(undef,0,1); #in-memory
+#ok $tt++, my $rdfstore=new RDFStore 'cooltest0',0,1; #on local disk
+#ok $tt++, my $rdfstore=new RDFStore 'cooltest0',0,1,0,1,'localhost'; #on remote (localhost) dbmsd
+# 48
+ok $tt++, ($rdfstore->size == 0);
+
+#ok $tt++, my $rdfstore1=new RDFStore; #in-memory
+# 49
+ok $tt++, my $rdfstore1=new RDFStore 'cooltest'; #on local disk
+#ok $tt++, my $rdfstore1=new RDFStore 'cooltest',0,0,0,1,'localhost'; #on remote (localhost) dbmsd
+# 50
+ok $tt++, ($rdfstore1->size == 0);
+
+# to be checked for the reification EXIST stuff (duplicates), assert both yes/no and so on....
+#ok $tt++, $rdfstore->insert( $st );
+#ok $tt++, $rdfstore->insert( $st2 );
+#ok $tt++, $rdfstore->insert( $st1 );
+#print "HERE????\n";
+
+#use Benchmark;
+#timethese( 10, {
+#test1 => sub {
+#for(1..10000) {
+#$rdfstore1->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/".$_, "Creator"), new RDFStore::Resource("http://description.org/schema/".$_, "Author"), new RDFStore::Literal("Ora Lassila") );
+#};
+#}
+#} );
+#exit;
+
+#51
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal( "Ora Lassila" ) ));
+ok $tt++, ($rdfstore1->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal( "Ora Lassila" ) ));
+
+#53
+ok $tt++, ($rdfstore->size == 1);
+ok $tt++, ($rdfstore1->size == 1);
+
+ok $tt++, ($rdfstore->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal( "Ora Lassila" ) ));
+ok $tt++, ($rdfstore1->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal( "Ora Lassila" ) ));
+
+ok $tt++, !($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal( "Ora Lassila" ) ));
+ok $tt++, !($rdfstore1->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal( "Ora Lassila" ) ));
+
+for ( my $i=0; $i<10 ; $i++) {
+ ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator".$i), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal("Ora Lassila".$i) ));
+ ok $tt++, ($rdfstore1->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator".$i), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal("Ora Lassila".$i) ));
+
+ ok $tt++, ($rdfstore->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator".$i), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal("Ora Lassila".$i) ));
+ ok $tt++, ($rdfstore1->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator".$i), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal("Ora Lassila".$i) ));
+
+ ok $tt++, ($rdfstore->remove( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator".$i), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal("Ora Lassila".$i) ));
+ ok $tt++, ($rdfstore1->remove( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator".$i), new RDFStore::Resource("http://description.org/schema/", "Author"), new RDFStore::Literal("Ora Lassila".$i) ));
+ };
+for ( my $i=0; $i<10 ; $i++) {
+ my $s = new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator".$i);
+ my $p = new RDFStore::Resource("http://description.org/schema/", "Author");
+ my $o = new RDFStore::Literal("Ora Lassila".$i);
+ my $st = new RDFStore::Statement( $s, $p, $o );
+
+ ok $tt++, ($rdfstore->insert( $st ));
+ ok $tt++, ($rdfstore1->insert( $st ));
+ ok $tt++, ($rdfstore->contains( $st ));
+ ok $tt++, ($rdfstore1->contains( $st ));
+ ok $tt++, ($rdfstore->remove( $st ));
+ ok $tt++, ($rdfstore1->remove( $st ));
+ };
+
+ok $tt++, $rdfstore->set_source_uri("hdhhdhddhdh");
+ok $tt++, ( $rdfstore->get_source_uri eq "hdhhdhddhdh");
+
+ok $tt++, ($rdfstore->size == 1);
+ok $tt++, ($rdfstore1->size == 1);
+
+my @today=( "TODAY:", 't'.time() );
+my $today = new RDFStore::Resource(@today);
+ok $tt++, ($rdfstore->set_context( $today ));
+ok $tt++, ($rdfstore1->set_context( $today ));
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+ok $tt++, ($rdfstore1->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+
+ok $tt++, ($rdfstore->get_context->equals( $today ) );
+ok $tt++, ($rdfstore1->get_context->equals( $today ) );
+ok $tt++, ($rdfstore->reset_context);
+ok $tt++, ($rdfstore1->reset_context);
+ok $tt++, ! (my $sg = $rdfstore->get_context);
+ok $tt++, ! (my $sg1 = $rdfstore1->get_context);
+
+my @yesterday=( "YESTERDAY:", 'y'.(time()-86400) );
+my $yesterday = new RDFStore::Resource(@yesterday);
+ok $tt++, ($rdfstore->set_context( $yesterday ));
+ok $tt++, ($rdfstore1->set_context( $yesterday ));
+ok $tt++, ($rdfstore->get_context->equals( $yesterday ) );
+ok $tt++, ($rdfstore1->get_context->equals( $yesterday ) );
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+ok $tt++, ($rdfstore1->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+ok $tt++, !($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+ok $tt++, !($rdfstore1->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+ok $tt++, ($rdfstore->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila"), $yesterday ));
+ok $tt++, ($rdfstore1->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila"), $yesterday ));
+ok $tt++, ($rdfstore->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila"), $today ));
+ok $tt++, ($rdfstore1->contains( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila"), $today ));
+
+ok $tt++, my $iterator = $rdfstore->elements;
+
+eval {
+ my $i=0;
+ while( my $s = $iterator->each ) {
+ #print $s->toString."\n";
+ $i++;
+ };
+ die unless($i==3);
+};
+ok $tt++, !$@;
+
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("This is a nice test to be checked; it is using ~!@#$%^&*() very funny chars and the free-text engine should cope with it.....") ));
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("This is a another nice test to be checked; Alberto is also in this now....") ));
+
+ok $tt++, ($rdfstore->reset_context);
+ok $tt++, ($rdfstore1->reset_context);
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+ok $tt++, ($rdfstore->remove( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila"), $yesterday ));
+ok $tt++, ($rdfstore->remove( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("art") ));
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Resource("art") ));
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("art and handycraft") ));
+ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Resource("art and handycraft") ));
+
+ok $tt++, ($iterator = $rdfstore->search( {
+ "s" => [ new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator") ],
+ "o" => [ new RDFStore::Literal("art") ],
+ } ));
+ok $tt++, ($iterator->size == 1);
+ok $tt++, ($iterator = $rdfstore->search( {
+ "s" => [ new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator") ],
+ "o" => [ new RDFStore::Resource("art") ],
+ } ));
+ok $tt++, ($iterator->size == 1);
+ok $tt++, ($iterator = $rdfstore->search( {
+ "s" => [ new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator") ],
+ "o" => [ new RDFStore::Literal("art and handycraft") ],
+ } ));
+ok $tt++, ($iterator->size == 1);
+ok $tt++, ($iterator = $rdfstore->search( {
+ "s" => [ new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator") ],
+ "words" => [ "art" ],
+ "words_op" => "and",
+ } ));
+ok $tt++, ($iterator->size == 2);
+ok $tt++, ($iterator = $rdfstore->search( {
+ "s" => [ new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator") ],
+ "words" => [ 'art','and','handycraft' ],
+ } ));
+ok $tt++, ($iterator->size == 3);
+
+ok $tt++, ($iterator = $rdfstore->search( {
+ "s" => [ new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator") ],
+ } ));
+ok $tt++, ($iterator = $rdfstore->search( {
+ "s" => [ new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator") ],
+ "words" => [ "This", "Alberto" ],
+ "words_op" => "and",
+ } ));
+ok $tt++, ($iterator->size == 1);
+
+eval {
+ my $i=0;
+ while( my $s = $iterator->each ) {
+ #print $s->toString."\n";
+ $i++;
+ };
+ die unless($i==1);
+};
+ok $tt++, !$@;
+
+eval {
+ my $i=0;
+ while( my $s = $iterator->each_subject ) {
+ #print $s->toString."\n";
+ $i++;
+ };
+ die "i=$i and not 1" unless($i==1);
+};
+ok $tt++, !$@;
+
+eval {
+ my $i=0;
+ while( my $s = $iterator->each_predicate ) {
+ #print $s->toString."\n";
+ $i++;
+ };
+ die unless($i==1);
+};
+ok $tt++, !$@;
+
+eval {
+ my $i=0;
+ while( my $s = $iterator->each_object ) {
+ #print $s->toString."\n";
+ $i++;
+ };
+ die unless($i==1);
+};
+ok $tt++, !$@;
+
+eval {
+ my $i=0;
+ while( my $s = $iterator->each_context ) {
+ #print $s->toString."\n";
+ $i++;
+ };
+ die unless($i==1);
+};
+ok $tt++, !$@;
+
+eval {
+my $i=0;
+for ( my $s = $iterator->first;
+ $iterator->hasnext;
+ $s = $iterator->next ) {
+ #print $s->toString."\n";
+ #die unless $iterator->remove;
+ $i++;
+ };
+#die if ($i <=> $iterator->size);
+};
+ok $tt++, !$@;
+
+ok $tt++, $iterator = $rdfstore->elements;
+
+eval {
+ my $i=0;
+ while( my $s = $iterator->each ) {
+ #print $s->toString."\n";
+ $i++;
+ };
+ die unless($i==8);
+};
+ok $tt++, !$@;
+
+ok $tt++, $iterator = new RDFStore::Iterator( $rdfstore );
+ok $tt++, my $iterator1 = new RDFStore::Iterator( $rdfstore1 );
+
+ok $tt++, ($iterator->size == $rdfstore->size);
+ok $tt++, ($iterator1->size == $rdfstore1->size);
+
+ok $tt++, my $rdfstore2=new RDFStore;
+ok $tt++, ($rdfstore2->set_context( $yesterday ));
+ok $tt++, ($rdfstore2->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "Creator"), new RDFStore::Literal("Ora Lassila") ));
+ok $tt++, ! ($rdfstore2->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/Creator"), new RDFStore::Literal("Ora Lassila") ));
+
+ok $tt++, (my $iterator2 = $iterator->duplicate);
+ok $tt++, ($iterator2 = $iterator2->complement );
+ok $tt++, ($iterator2->size == 0 );
+ok $tt++, (my $iterator3 = $iterator2->intersect( $iterator )->intersect( $iterator )->subtract( $iterator )->unite( $iterator )->exor( $iterator )->complement );
+
+eval {
+my $i=0;
+for ( my $s = $iterator2->first;
+ $iterator2->hasnext;
+ $s = $iterator2->next ) {
+ #print $s->toString."\n";
+ die unless $iterator2->remove;
+ $i++;
+ };
+#die if ($i <=> $iterator2->size);
+};
+ok $tt++, !$@;
+
+eval {
+my $i=0;
+for ( my $s = $iterator3->first;
+ $iterator3->hasnext;
+ $s = $iterator3->next ) {
+ #print $s->toString."\n";
+ die unless $iterator3->remove;
+ $i++;
+ };
+#die if ($i <=> $iterator3->size);
+};
+ok $tt++, !$@;
+
+# integer range searches
+for my $i ( qw{ 1 11 22 111 123 222 1111 2222 33 3333 } ) {
+ ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "value"), new RDFStore::Literal( $i ) ));
+ };
+
+ok $tt++, ($iterator = $rdfstore->search( {
+ "ranges" => [ "33" ],
+ "ranges_op" => "a > b"
+ } ));
+#print $iterator->size."\n";
+ok $tt++, ($iterator->size == 6);
+
+ok $tt++, ($iterator = $rdfstore->search( {
+ "ranges" => [ "33" ],
+ "ranges_op" => "a != b"
+ } ));
+#print $iterator->size."\n";
+ok $tt++, ($iterator->size == 9);
+
+# date range searches
+for my $i ( 1..30 ) {
+ ok $tt++, ($rdfstore->insert( new RDFStore::Resource("http://www.w3.org/Home/Lassila/", "Creator"), new RDFStore::Resource("http://description.org/schema/", "date"), new RDFStore::Literal( "2004-11-".sprintf("%02d",$i),0, undef, "http://www.w3.org/2001/XMLSchema#date" ) ));
+ };
+
+ok $tt++, ($iterator = $rdfstore->search( {
+ "ranges" => [ "2004-11-15" ],
+ "ranges_op" => "a < b"
+ } ));
+#print $iterator->size."\n";
+ok $tt++, ($iterator->size == 14);
+
+ok $tt++, ($iterator = $rdfstore->search( {
+ "ranges" => [ "2004-11-10", "2004-11-15" ],
+ "ranges_op" => "a < b < c"
+ } ));
+#print $iterator->size."\n";
+ok $tt++, ($iterator->size == 4);
Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/02_parser.t
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/02_parser.t?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/02_parser.t (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/02_parser.t Fri Apr 13 01:56:01 2007
@@ -0,0 +1,126 @@
+BEGIN {print "1..13\n";}
+END { print "not ok 1\n" unless $::loaded; RDFStore::debug_malloc_dump(); };
+
+my $a = "";
+local $SIG{__WARN__} = sub {$a = $_[0]} ;
+
+sub ok
+{
+ my $no = shift ;
+ my $result = shift ;
+
+ print "not " unless $result ;
+ print "ok $no\n" ;
+}
+
+use RDFStore::Parser::SiRPAC;
+use RDFStore::Parser::NTriples;
+use RDFStore::NodeFactory;
+
+$loaded = 1;
+print "ok 1\n";
+
+my $tt=2;
+ok $tt++, my $parser = new RDFStore::Parser::SiRPAC(ProtocolEncoding => 'ISO-8859-1',NodeFactory => new RDFStore::NodeFactory());
+ok $tt++, my $parser1 = new RDFStore::Parser::NTriples(NodeFactory => new RDFStore::NodeFactory());
+ok $tt++, my $parser2 = new RDFStore::Parser::SiRPAC(Style => 'RDFStore::Parser::Styles::RDFStore::Model', NodeFactory => new RDFStore::NodeFactory());
+ok $tt++, my $parser3 = new RDFStore::Parser::NTriples(Style => 'RDFStore::Parser::Styles::RDFStore::Model', NodeFactory => new RDFStore::NodeFactory());
+
+my $rdfstring =<<"End_of_RDF;";
+<?xml version='1.0' encoding='ISO-8859-1'?>
+<!DOCTYPE rdf:RDF [
+ <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
+ <!ENTITY a 'http://description.org/schema/'>
+]>
+<rdf:RDF
+ xmlns:rdf="&rdf;" xmlns:a="&a;">
+<rdf:Description rdf:about="http://www.w3.org">
+ <a:Date>1998-10-03T02:27</a:Date>
+ <a:Publisher>World Wide Web Consortium</a:Publisher>
+ <a:Title>W3C Home Page</a:Title>
+ <a:memyI xml:space="preserve"> </a:memyI>
+ <a:albe rdf:parseType="Literal"><this xmlns:is="http://iscool.org" xmlns="http://anduot.edu" is:me="a test">
+Hei!!<me you="US"><you><a><b/></a></you>aaaa</me>
+
+ciao!!!
+<test2/>
+
+---lsls;s</this></a:albe>
+ <a:ee>EEEEE</a:ee>
+ <a:bb rdf:parseType="Literal"><a:raffa xmlns:a="&a;">Ella</a:raffa></a:bb>
+ <a:test rdf:nodeID="test222er"/>
+</rdf:Description>
+
+<a:TEST rdf:nodeID="test222er"/>
+
+</rdf:RDF>
+End_of_RDF;
+
+my $rdfntriplesstring =<<"End_of_RDF;";
+<http://example.org/foo> <http://example.org/bar> "10"^^<http://www.w3.org/2001/XMLSchema#integer> .
+<http://example.org/foo> <http://example.org/baz> "10"\@fr^^<http://www.w3.org/2001/XMLSchema#integer> .
+<http://www.w3.org/2000/10/rdf-tests/rdfcore/rdfms-xml-literal-namespaces/test001.rdf#John_Smith> <http://my.example.org/Name> "\n <html:h1 xmlns:html=\"http://NoHTML.example.org\">\n <b xmlns=\"http://www.w3.org/1999/xhtml\">John</b>\n </html:h1>\n "^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+End_of_RDF;
+
+eval {
+ $parser->setHandlers(
+ Init => sub { "INIT"; },
+ Final => sub { "FINAL"; },
+ Assert => sub { "STATEMENT"; },
+ Start_XML_Literal => sub { $_[0]->recognized_string if($_[0]->can('recognized_string')); },
+ Stop_XML_Literal => sub { $_[0]->recognized_string if($_[0]->can('recognized_string')); },
+ Char_Literal => sub { $_[0]->recognized_string if($_[0]->can('recognized_string')); }
+ );
+};
+ok $tt++, !$@;
+
+eval {
+ $parser->parsestring($rdfstring);
+};
+ok $tt++, !$@;
+
+eval {
+ $parser1->setHandlers(
+ Init => sub { "INIT"; },
+ Final => sub { "FINAL"; },
+ Assert => sub { "STATEMENT"; },
+ Start_XML_Literal => sub { $_[0]->recognized_string if($_[0]->can('recognized_string')); },
+ Stop_XML_Literal => sub { $_[0]->recognized_string if($_[0]->can('recognized_string')); },
+ Char_Literal => sub { $_[0]->recognized_string if($_[0]->can('recognized_string')); }
+ );
+};
+ok $tt++, !$@;
+
+eval {
+ $parser1->parsestring($rdfntriplesstring);
+};
+ok $tt++, !$@;
+
+eval {
+ $parser2->parsestring($rdfstring);
+ #print $parser2->parsestring($rdfstring)->serialize(undef,'RDF/XML');
+ #print $parser2->parsestring($rdfstring)->serialize(undef,'N-Triples');
+};
+ok $tt++, !$@;
+
+eval {
+ $parser3->parsestring($rdfntriplesstring);
+ #print $parser3->parsestring($rdfntriplesstring)->serialize(undef,'RDF/XML');
+ #print $parser3->parsestring($rdfntriplesstring)->serialize(undef,'N-Triples');
+};
+ok $tt++, !$@;
+
+# bNode re-write test
+eval {
+ my %uri_map = ( 'test222er' => 'http://foo.org/test.html' );
+ $parser2->setHandlers(
+ manage_bNodes => sub { $_[1]->createResource($uri_map{$_[2]}); }
+ );
+};
+ok $tt++, !$@;
+
+eval {
+ $parser2->parsestring($rdfstring);
+ #print $parser2->parsestring($rdfstring)->serialize(undef,'RDF/XML');
+};
+ok $tt++, !$@;
Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/03_model.t
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/03_model.t?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/03_model.t (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/03_model.t Fri Apr 13 01:56:01 2007
@@ -0,0 +1,353 @@
+use strict ;
+
+BEGIN { print "1..130\n"; };
+END { print "not ok 1\n" unless $::loaded; RDFStore::debug_malloc_dump(); eval{ rmtree('cooltest'); }; };
+
+my $a = "";
+local $SIG{__WARN__} = sub {$a = $_[0]} ;
+
+sub ok
+{
+ my $no = shift ;
+ my $result = shift ;
+
+ print "not " unless $result ;
+ print "ok $no\n" ;
+}
+
+sub docat
+{
+ my $file = shift;
+ local $/ = undef;
+ open(CAT,$file) || die "Cannot open $file:$!";
+ my $result = <CAT>;
+ close(CAT);
+ return $result;
+};
+
+#$::debug=1;
+
+umask(0);
+
+use RDFStore::NodeFactory;
+use RDFStore::RDFNode;
+use RDFStore::Literal;
+use RDFStore::Model;
+
+use File::Path qw(rmtree);
+
+eval{
+rmtree('cooltest');
+};
+
+$::loaded = 1;
+print "ok 1\n";
+
+my $tt=2;
+
+ok $tt++, my $factory= new RDFStore::NodeFactory();
+
+#node
+ok $tt++, my $node = new RDFStore::RDFNode();
+
+#literals
+ok $tt++, my $literal = new RDFStore::Literal('cooltest',0,"en");
+ok $tt++, my $literal1 = new RDFStore::Literal('esempio1',1,"it");
+ok $tt++, !($literal->getParseType);
+ok $tt++, ($literal->getLang eq 'en');
+ok $tt++, ($literal1->getParseType);
+ok $tt++, ($literal1->getLang eq 'it');
+ok $tt++, ($literal->getLabel eq 'cooltest');
+ok $tt++, ($literal1->getLabel eq 'esempio1');
+ok $tt++, ($literal->toString eq 'cooltest');
+ok $tt++, ($literal1->toString eq 'esempio1');
+ok $tt++, ($literal->getDigest eq $literal1->getDigest) ? 0 : 1;
+
+ok $tt++, my $statement = $factory->createStatement(
+ $factory->createResource('http://www.w3.org/Home/Lassila'),
+ $factory->createResource('http://description.org/schema/','Creator'),
+ $factory->createLiteral('Ora Lassila') );
+ok $tt++, my $subject = $statement->subject;
+ok $tt++, ($subject->getLabel eq 'http://www.w3.org/Home/Lassila');
+ok $tt++, ($subject->getURI eq 'http://www.w3.org/Home/Lassila');
+ok $tt++, ($subject->toString eq 'http://www.w3.org/Home/Lassila');
+ok $tt++, ($subject->getNamespace eq 'http://www.w3.org/Home/');
+ok $tt++, ($subject->getLocalName eq 'Lassila');
+ok $tt++, my $predicate = $statement->predicate;
+ok $tt++, ($predicate->getLabel eq 'http://description.org/schema/Creator');
+ok $tt++, ($predicate->getURI eq 'http://description.org/schema/Creator');
+ok $tt++, ($predicate->toString eq 'http://description.org/schema/Creator');
+ok $tt++, ($predicate->getNamespace eq 'http://description.org/schema/');
+ok $tt++, ($predicate->getLocalName eq 'Creator');
+ok $tt++, my $object = $statement->object;
+ok $tt++, ($object->getLabel eq 'Ora Lassila');
+ok $tt++, ($object->toString eq 'Ora Lassila');
+
+ok $tt++, !(defined $statement->getNamespace);
+ok $tt++, (defined $statement->getLocalName);
+
+my $hc = $statement->getLocalName; # undefined -- se above..
+
+# ok $tt++, ($statement->getLocalName eq $hc);
+ok $tt++, (defined ($statement->getLocalName));
+#ok $tt++,($statement->getLabel eq $hc);
+ok $tt++, (defined ($statement->getLabel));
+#ok $tt++, ($statement->getURI eq $hc);
+ok $tt++, (defined ($statement->getURI));
+
+ok $tt++, my $ntriple = $factory->createNTriple( '<http://www.w3.org/Home/Lassila> <http://description.org/schema/Creator> "Ora Lassila" .' );
+ok $tt++, ( $statement->equals( $ntriple ) );
+
+ok $tt++, my $ll = $factory->createLiteral('Ora Lissala');
+ok $tt++, my $statement0 = $factory->createStatement(
+ $factory->createResource('http://www.w3.org/Home/Lassila'),
+ $factory->createResource('http://description.org/schema/','Author'),
+ $ll
+ );
+
+ok $tt++, my $ntriple0 = $factory->createNTriple( '<http://www.w3.org/Home/Lassila> <http://description.org/schema/Author> "'.$ll->toString.'" .' );
+ok $tt++, ( $statement0->equals( $ntriple0 ) );
+
+ok $tt++, my $ntriple1 = $factory->createNTriple( '<http://www.w3.org/Home/Lassila> <http://description.org/schema/Creator> "Ora Lassila"@en .' );
+ok $tt++, ( $ntriple1->object->getLang eq 'en' );
+ok $tt++, !($ntriple1->object->getParseType);
+
+ok $tt++, my $ntriple2 = $factory->createNTriple( '<http://www.w3.org/Home/Lassila> <http://description.org/schema/age> "<xml>24</xml>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .' );
+ok $tt++, ($ntriple2->object->getParseType);
+
+ok $tt++, my $ntriple3 = $factory->createNTriple( '<http://www.w3.org/Home/Lassila> <http://description.org/schema/age> "2"^^<http://www.w3.org/2001/XMLSchema#integer> .' );
+ok $tt++, !($ntriple3->object->getParseType);
+ok $tt++, ( $ntriple3->object->getDataType eq "http://www.w3.org/2001/XMLSchema#integer" );
+
+ok $tt++, my $ntriple4 = $factory->createNTriple( '<http://www.w3.org/Home/Lassila> <http://description.org/schema/Name> "Peter Pan"@en^^<http://www.w3.org/2001/XMLSchema#string> .' );
+ok $tt++, ( $ntriple4->object->getLang eq 'en' );
+ok $tt++, !($ntriple4->object->getParseType);
+ok $tt++, ( $ntriple4->object->getDataType eq "http://www.w3.org/2001/XMLSchema#string" );
+
+ok $tt++, my $statement1 = $factory->createStatement(
+ $factory->createResource('http://www.w3.org/Home/Lassila'),
+ $factory->createResource('http://description.org/schema/','Author'),
+ $factory->createLiteral('Alberto Reggiori') );
+
+ok $tt++, my $statement2 = $factory->createStatement(
+ $factory->createResource('http://www.altavista.com'),
+ $factory->createResource('http://somewhere.org/schema/1.0/#','author'),
+ $factory->createLiteral('me') );
+
+ok $tt++, my $statement3 = $factory->createStatement(
+ $factory->createResource('http://www.google.com'),
+ $factory->createResource('http://somewhere.org/schema/1.0/#creator'),
+ $factory->createLiteral('you and me') );
+
+ok $tt++, my $statement4 = $factory->createStatement(
+ $factory->createResource('google'),
+ $factory->createResource('http://somewhere.org/schema/1.0/#creator'),
+ $factory->createLiteral('meMyselfI') );
+
+# should be the same as the one just above
+ok $tt++, my $statement4a = $factory->createStatement(
+ $factory->createResource('google'),
+ $factory->createResource('http://somewhere.org/schema/1.0/#','creator'),
+ $factory->createLiteral('meMyselfI') );
+
+ok $tt++, my $statement5 = $factory->createStatement(
+ $factory->createUniqueResource(),
+ $factory->createOrdinal(1),
+ $factory->createLiteral('') );
+
+ok $tt++, my $model = new RDFStore::Model( Name => 'cooltest',
+ #Host => 'localhost',
+ nodeFactory => $factory,
+ Sync => 1,
+ FreeText => 1
+ );
+ok $tt++, $model->setSourceURI('http://somewhere.org/');
+my $now='t'.time;
+my $ctx = $factory->createResource($now);
+ok $tt++, $model->setContext($ctx);
+ok $tt++, ( $factory->createResource($now)->equals( $model->getContext ) );
+ok $tt++, ($model->getSourceURI eq 'http://somewhere.org/');
+ok $tt++, ($model->toString eq 'Model[http://somewhere.org/]');
+ok $tt++, !(defined $model->getNamespace);
+my @date = gmtime( time() );
+my $nowdateTime = sprintf( "%04d-%02d-%02dT%02d:%02d:%02dZ", 1900+int($date[5]), 1+int($date[4]),
+ int($date[3]), int($date[2]), int($date[1]), int($date[0]) );
+ok $tt++, ! $model->ifModifiedSince( $nowdateTime );
+sleep(1);
+ok $tt++, $model->add($statement);
+ok $tt++, $model->ifModifiedSince( $nowdateTime );
+@date = gmtime( time() );
+$nowdateTime = sprintf( "%04d-%02d-%02dT%02d:%02d:%02dZ", 1900+int($date[5]), 1+int($date[4]),
+ int($date[3]), int($date[2]), int($date[1]), int($date[0]) );
+ok $tt++, ! $model->ifModifiedSince( $nowdateTime );
+ok $tt++, $model->add($statement0);
+ok $tt++, $model->add($statement1);
+ok $tt++, $model->add($statement2);
+ok $tt++, $model->add($statement3);
+ok $tt++, $model->add($statement4);
+ok $tt++, ! $model->add($statement4); #not done due to context above :)
+ok $tt++, ! $model->add($statement4);
+ok $tt++, ! $model->add($statement4a); #not done because same statemnt as above
+ok $tt++, $model->resetContext(); #reset it for a moment
+ok $tt++, $model->add($statement5);
+ok $tt++, $model->setContext($factory->createResource($now));
+ok $tt++, !($model->isEmpty);
+ok $tt++, ($model->size == 7);
+ok $tt++, ($model->contains($statement1,$ctx));
+ok $tt++, ($model->isMutable);
+
+eval {
+ my $modeldd = new RDFStore::Model( Name => 'cooltest',
+ nodeFactory => $factory,
+ Mode => 'r' #read-only
+ );
+ #my $ee = $modeldd->elements;
+ #while (my $s = $ee->each ) {
+ # print $s->toString,"\n";
+ # };
+};
+ok $tt++, !$@;
+
+ok $tt++, my $found = $model->find($statement->subject,$statement->predicate,$statement->object);
+#ok $tt++, my $found = $model->find($statement->subject,undef,$statement->object);
+eval {
+ my ($num) = $found->elements;
+ die unless($num->size==1);
+ my $ss = $num->first;
+ #die unless( $model->contains($ss) );
+ #die unless( $found->contains($ss) );
+ die unless($ss->equals($statement));
+};
+ok $tt++, !$@;
+
+eval {
+ my $st;
+ die unless($st=$found->elements);
+ my $ss=$st->first;
+ #die unless( $model->contains($ss) );
+ #die unless( $found->contains($ss) );
+ die unless($ss->equals($statement));
+};
+ok $tt++, !$@;
+
+# unite
+my $mu=$model->duplicate->unite($found);
+ok $tt++, ($mu->size==7);
+# intersect
+my $mi=$model->duplicate->intersect($found);
+ok $tt++, ($mi->size==1);
+#print "SIZE=".$model->size."=".$mi->size."\n";
+#my $ee = $mi->elements;
+#for ( my $e = $ee->first; $ee->hasnext; $e= $ee->next ) {
+# print "----->".$e->toString."\n";
+# };
+# subtract
+my $ms=$model->duplicate->subtract($found);
+ok $tt++, ($ms->size==6);
+
+ok $tt++, my $kk = $found->find()->find()->find();
+ok $tt++, ($kk->size==1);
+ok $tt++, my $kk1 = $found->find(undef,$statement->predicate)->find()->find($statement->subject);
+ok $tt++, ($kk1->size==1);
+ok $tt++, my $kk2 = $found->find(undef,$statement->predicate)->find()->find($statement->subject)->intersect($kk1);
+ok $tt++, ($kk2->size==1);
+ok $tt++, my $kk3 = $found->find(undef,$statement->predicate)->find()->find($statement->subject)->unite($kk1);
+ok $tt++, ($kk3->size==1);
+
+#my $ee = $kk->elements;
+#print "ee=".$ee->size."\n";
+#for ( my $e = $ee->first; $ee->hasnext; $e= $ee->next ) {
+# print "----->".$e->toString."\n";
+# };
+
+ok $tt++, my $statement6 = $factory->createStatement(
+ $factory->createUniqueResource(),
+ $factory->createOrdinal(3),
+ $factory->createLiteral('test6') );
+ok $tt++, my $statement7 = $factory->createStatement(
+ $factory->createResource("http://rdfstore.sf.net"),
+ $factory->createResource('http://somewhere.org/schema/1.0/#demolink'),
+ $factory->createResource("http://demo.asemantics.com/rdfstore") );
+
+ok $tt++, $found->add($statement6);
+ok $tt++, $found->add($statement7);
+ok $tt++, ($found->contains($statement6));
+ok $tt++, ($found->contains($statement7));
+ok $tt++, ($found->size == 3);
+ok $tt++, $found->remove($statement6);
+ok $tt++, ($found->size == 2);
+ok $tt++, !($found->contains($statement6));
+
+my $found1 = $found->find(undef,undef,$statement7->object);
+eval {
+ my($num) = $found1->elements;
+ die unless($num->size==1);
+ my $ss = $num->first;
+ die unless($ss->equals($statement7));
+};
+ok $tt++, !$@;
+
+eval {
+ my $r=0;
+ my $num = $found1->elements;
+ while ( my $st = $num->each ) {
+ #print $st->toString,"\n";
+ $r++;
+ };
+ die unless($r == 1);
+};
+ok $tt++, !$@;
+
+ok $tt++, my $model1 = $model->duplicate();
+ok $tt++, ($model1->size==$model->size);
+
+ok $tt++, my $found2 = $model1->find($statement2->subject,undef,$statement2->object);
+eval {
+ my($num) = $found2->elements;
+ die unless($num->size==1);
+};
+ok $tt++, !$@;
+
+#free-text on literals
+ok $tt++, my $found3=$model->find(undef,undef,undef,undef,1,'me','you');
+eval {
+ my ($num) = $found3->elements;
+ die unless($num->size==1);
+};
+ok $tt++, !$@;
+
+#contexts stuff
+ok $tt++, ($model->getContext->toString eq $now);
+
+#cool stuff!
+ok $tt++, my $found4=$model->find(undef,undef,undef,$model->getContext);
+eval {
+ my($num) = $found4->elements;
+ die unless($num->size==6);
+};
+ok $tt++, !$@;
+
+ok $tt++, my $found5=$model->find($statement5->subject,$statement5->predicate,$statement5->object,$model->getContext);
+eval {
+ my($num) = $found5->elements;
+ die unless($num->size==0);
+};
+ok $tt++, !$@;
+
+ok $tt++, (!($model->contains($statement5,$model->getContext)));
+ok $tt++, $model->resetContext;
+ok $tt++, ($model->contains($statement5));
+
+ok $tt++, $model->add($statement5,undef,undef,$factory->createResource($now));
+ok $tt++, $model->contains($statement5,$factory->createResource($now));
+ok $tt++, $model->remove($statement5,$factory->createResource($now));
+ok $tt++, (!($model->contains($statement5,$factory->createResource($now))));
+
+#for (1..100000) {
+# my $st = $factory->createStatement(
+# $factory->createUniqueResource(),
+# $factory->createOrdinal($_),
+# $factory->createLiteral('') );
+# $model->add($st);
+##print STDERR $_,"\n";
+#};
Added: incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/04_rdql.t
URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/04_rdql.t?view=auto&rev=528394
==============================================================================
--- incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/04_rdql.t (added)
+++ incubator/triplesoup/donations/TRIPLES-3-RDFStore/t/04_rdql.t Fri Apr 13 01:56:01 2007
@@ -0,0 +1,609 @@
+use strict ;
+
+BEGIN { print "1..127\n"; };
+END { print "not ok 1\n" unless $::loaded; RDFStore::debug_malloc_dump(); };
+
+my $a = "";
+local $SIG{__WARN__} = sub {$a = $_[0]} ;
+
+sub ok
+{
+ my $no = shift ;
+ my $result = shift ;
+
+ print "not " unless $result ;
+ print "ok $no\n" ;
+}
+
+sub docat
+{
+ my $file = shift;
+ local $/ = undef;
+ open(CAT,$file) || die "Cannot open $file:$!";
+ my $result = <CAT>;
+ close(CAT);
+ return $result;
+};
+
+$::debug=0;
+
+umask(0);
+
+use RDQL::Parser;
+use DBI;
+use RDFStore::NodeFactory;
+use RDFStore::Parser::SiRPAC;
+use File::Path qw(rmtree);
+
+$::loaded = 1;
+print "ok 1\n";
+
+my $tt=2;
+
+#test the parser
+eval {
+ while(<t/rdql-tests/test-*>) {
+ ok $tt++, my $parser = new RDQL::Parser();
+ $parser->parse(docat($_));
+ };
+};
+ok $tt++, !$@;
+
+my $factory= new RDFStore::NodeFactory();
+
+#RDQL queries
+ok $tt++, my $dbh= DBI->connect("DBI:RDFStore:", "root", 0, { nodeFactory => $factory } );
+
+ok $tt++, my $query = $dbh->prepare(<<QUERY);
+SELECT ?title, ?link
+FROM <file:t/rdql-tests/rdf/rss10.php>
+WHERE
+ (?item, <rdf:type>, <rss:item>),
+ (?item, <rss::title>, ?title),
+ (?item, <rss::link>, ?link)
+USING
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ rss for <http://purl.org/rss/1.0/>
+QUERY
+ok $tt++, $query->execute();
+my ($title,$link);
+ok $tt++, $query->bind_columns(\$title, \$link);
+my $kk=0;
+eval {
+while ($query->fetch()) {
+ print "title=",$title->toString," link=".$link->toString,"\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (8 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?link, ?title
+FROM <file:t/rdql-tests/rdf/rss10.php>
+WHERE
+ (?item, <rdf:type>, <rss:item>),
+ (?item, <rss::title>, %"February"% ),
+ (?item, <rss::title>, ?title ),
+ (?item, <rss::link>, ?link)
+#ORDER BY ( ?title =~ m/1/ )
+ORDER BY ?title
+LIMIT 10
+OFFSET 0
+USING
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ rss for <http://purl.org/rss/1.0/>
+QUERY
+ok $tt++, $query->execute(); # still getting silly perl warning: Argument "February" isn't numeric in subroutine entry at blib/lib/DBD/RDFStore.pm line 315. :-(
+ok $tt++, $query->bind_columns(\$link,\$title);
+$kk=0;
+eval {
+while ($query->fetch()) {
+ print "title=",$title->toString," link=".$link->toString,"\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (4 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?title, ?link
+FROM <file:t/rdql-tests/rdf/rss10.php>
+WHERE
+ (?item, <rdf:type>, <rss:item>),
+ (?item, <rss::title>, ?title),
+ (?item, <rss::link>, ?link)
+AND
+ ?title LIKE /(4 February)/i
+USING
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ rss for <http://purl.org/rss/1.0/>
+QUERY
+ok $tt++, $query->execute();
+ok $tt++, $query->bind_columns(\$title,\$link);
+$kk=0;
+eval {
+while ($query->fetch()) {
+ print "title=",$title->toString," link=".$link->toString,"\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (1 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?x, ?title, ?a, ?moddate, ?createddate, ?name, ?creatormail
+FROM <file:t/rdql-tests/rdf/dc3.rdf>
+WHERE
+ ( ?x, <dc:title>, ?title),
+ ( ?x, <dcq:modified>, ?m),
+ ( ?m, <rdf:value>, ?moddate),
+ ( ?x, <dcq:created>, ?cd),
+ ( ?cd, <rdf:value>, ?createddate),
+ ( ?x, <dcq:abstract>, ?a),
+ ( ?cr, <vcard:FN>, ?name),
+ ( ?x, <dc:creator>, ?cr),
+ ( ?cr, <vcard:EMAIL>, ?creatormail)
+USING dcq for <http://dublincore.org/2000/03/13/dcq#>,
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ vcard for <http://www.w3.org/2001/vcard-rdf/3.0#>,
+ dc for <http://purl.org/dc/elements/1.1/>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (1 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?sal, ?t, ?x
+FROM <file:t/rdql-tests/rdf/jobs-rss.rdf>,
+ <file:t/rdql-tests/rdf/jobs.rss>
+WHERE
+ (?x, <job:advertises>, ?y),
+ (?y, <job:title>, ?t) ,
+ (?y, <job:salary>, ?sal)
+AND (?sal == 100000) && (?x eq <http://www.lotsofjobs.com/job2>)
+USING job for <http://ilrt.org/discovery/2000/11/rss-query/jobvocab.rdf#>
+
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (1 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT
+ ?title_value, ?title_language,
+ ?subject_value,?subject_language,
+ ?description_value, ?description_language,
+ ?language,
+ ?identifier
+FROM
+ <file:t/rdql-tests/rdf/example10.xml>
+WHERE
+ ( ?tt, <rdf:value>, ?title_value),
+ ( ?x, <dc:title>, ?tt),
+ ( ?ttl, <dcq:RFC1766>, ?title_language),
+ ( ?ss1, <etbthes:ETBT>, ?ss2),
+ ( ?x, <dc:subject>, ?ss1),
+ ( ?ss2, <rdf:value>, ?subject_value),
+ ( ?tt, <dc:language>, ?ttl),
+ ( ?ss2, <dc:language>, ?ss3),
+ ( ?ss3, <dcq:RFC1766>, ?subject_language),
+ ( ?x, <dc:description>, ?dd),
+ ( ?ddl, <dcq:RFC1766>, ?description_language),
+ ( ?dd, <rdf:value>, ?description_value),
+ ( ?x, <dc:identifier>, ?identifier),
+ ( ?dd, <dc:language>, ?ddl),
+ ( ?ll1, <dcq:RFC1766>, ?language),
+ ( ?x, <dc:language>, ?ll1)
+USING
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ rdfs for <http://www.w3.org/2000/01/rdf-schema#>,
+ dc for <http://purl.org/dc/elements/1.1/>,
+ dcq for <http://purl.org/dc/terms/>,
+ dct for <http://purl.org/dc/dcmitype/>,
+ etb for <http://eun.org/etb/elements/>,
+ etbthes for <http://eun.org/etb/thesaurus/elements/>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (4 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT
+ ?subject_keywords_value,?subject_keywords_language
+FROM
+ <file:t/rdql-tests/rdf/example10.xml>
+WHERE
+ ( ?x, <dc:subject>, ?ss1),
+ ( ?ss1, <etb:Keywords>, ?ss2),
+ ( ?ss2, <rdf:value>, ?subject_keywords_value),
+ ( ?ss2, <dc:language>, ?ss3),
+ ( ?ss3, <dcq:RFC1766>, ?subject_keywords_language)
+USING
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ rdfs for <http://www.w3.org/2000/01/rdf-schema#>,
+ dc for <http://purl.org/dc/elements/1.1/>,
+ dcq for <http://purl.org/dc/terms/>,
+ dct for <http://purl.org/dc/dcmitype/>,
+ etb for <http://eun.org/etb/elements/>,
+ etbthes for <http://eun.org/etb/thesaurus/elements/>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (3 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT
+ ?subject_keywords_value,?subject_keywords_language
+FROM
+ <file:t/rdql-tests/rdf/example10.xml>
+WHERE
+ ( ?x, <dc:subject>, ?ss1),
+ ( ?ss1, <etb:BREAKQUERY>, ?ss2),
+ ( ?ss2, <rdf:value>, ?subject_keywords_value),
+ ( ?ss2, <dc:language>, ?ss3),
+ ( ?ss3, <dcq:RFC1766>, ?subject_keywords_language)
+USING
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ rdfs for <http://www.w3.org/2000/01/rdf-schema#>,
+ dc for <http://purl.org/dc/elements/1.1/>,
+ dcq for <http://purl.org/dc/terms/>,
+ dct for <http://purl.org/dc/dcmitype/>,
+ etb for <http://eun.org/etb/elements/>,
+ etbthes for <http://eun.org/etb/thesaurus/elements/>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (0 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?x, ?y, ?title1, ?title2, ?abstract1, ?abstract2, ?lastmod
+FROM
+ <file:t/rdql-tests/rdf/features_fix.rdf>,
+ <file:t/rdql-tests/rdf/humans_fix.rdf>
+WHERE
+ (?x, <dc:title>, ?title1),
+ (?y, <dc:title>, ?title2),
+ (?x, <dcq:abstract>, ?abstract1),
+ (?y, <dcq:abstract>, ?abstract2),
+ (?x, <dcq:references>, ?y),
+ (?y, <dcq:modified>, ?m),
+ (?m, <rdf:value>, ?lastmod)
+USING dcq for <http://dublincore.org/2000/03/13/dcq#>,
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ vcard for <http://www.w3.org/2001/vcard-rdf/3.0#>,
+ dc for <http://purl.org/dc/elements/1.1/>
+QUERY
+ok $tt++, $query->execute();
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ };
+};
+ok $tt++, !$@;
+ok $tt++, $query->finish();
+
+if(0){
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?x, ?title, ?a, ?moddate, ?createddate, ?name, ?creatormail
+FROM <file:t/rdql-tests/rdf/dc.rdf>,
+ <file:t/rdql-tests/rdf/dc1.rdf>
+ WHERE
+ (?x, <dc:title>, ?title),
+ (?x, <dcq:abstract>, ?a),
+ (?x, <dcq:modified>, ?m),
+ (?x, <dcq:created>, ?cd),
+ (?m, <rdf:value>, ?moddate),
+ (?cd, <rdf:value>, ?createddate),
+ (?x, <dc:creator>, ?cr),
+ (?cr, <vcard:FN>, ?name),
+ (?cr, <vcard:EMAIL>, ?creatormail)
+USING dcq for <http://dublincore.org/2000/03/13/dcq#>,
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ vcard for <http://www.w3.org/2001/vcard-rdf/3.0#>,
+ dc for <http://purl.org/dc/elements/1.1/>
+QUERY
+ok $tt++, $query->execute();
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ };
+};
+ok $tt++, !$@;
+ok $tt++, $query->finish();
+};
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?name, ?info
+SOURCE <file:t/rdql-tests/rdf/swws2001-07-30.rdf>
+WHERE
+(?cal, <dc::source>, <http://www.SemanticWeb.org/SWWS/program/>),
+(?cal, <ical::VEVENT-PROP>, ?event),
+(?event, <ical::LOCATION>, ?geo),
+(?geo, <ical::GEO-NAME>, ?text),
+(?text, <rdf::value>, ?name),
+(?geo, <rdfs::seeAlso>, ?info)
+USING
+rdf FOR <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+rdfs FOR <http://www.w3.org/2000/01/rdf-schema#>,
+ical FOR <http://ilrt.org/discovery/2001/06/schemas/ical-full/hybrid.rdf#>,
+util FOR <http://ilrt.org/discovery/2001/06/schemas/swws/index.rdf#>,
+foaf FOR <http://xmlns.com/foaf/0.1/>,
+dc FOR <http://purl.org/dc/elements/1.1/>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (19 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?link
+SOURCE <file:t/rdql-tests/rdf/lastampaEconomia.rdf>
+WHERE
+(?x, <rdf:type>, <rss:item>),
+(?x, <rss::title>, ?title),
+(?x, <rss::link>, ?link)
+AND ?title LIKE /incombe/i
+USING
+rss for <http://purl.org/rss/1.0/>,
+rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ print join(',',map { $_->toString } @row)."\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (1 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT *
+SOURCE <file:t/rdql-tests/rdf/lastampaEconomia.rdf>
+WHERE
+(?x, <rdf:type>, <rss:item>),
+(?x, <rss::title>, ?title),
+(?x, <rss::link>, ?link)
+USING
+rss for <http://purl.org/rss/1.0/>,
+rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+QUERY
+ok $tt++, $query->execute();
+ok $tt++, ($#{$query->{NAME}}==2);
+$kk=0;
+eval {
+while (my @a = $query->fetchrow_array()) {
+ die
+ unless(scalar(@a)>0);
+ map { print $_->toString,"\n" } @a
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (19 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?y
+SOURCE <file:t/rdql-tests/rdf/lastampaEconomia.rdf>
+WHERE
+(?x, <rdf:type>, <rss:item>),
+(?x, <rss::title>, ?title),
+(?x, <rss::link>, ?link)
+USING
+rss for <http://purl.org/rss/1.0/>,
+rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ die
+ unless(scalar(@row)>0);
+ map { print $_->toString,"\n" } @row
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (19 == $kk);
+ok $tt++, $query->finish();
+
+# test context/statement grouping RDQL support
+# NOTE: once the RDF Core WG will add proper context support to the XML/RDF xyntax we will be able to do it inside the SiRPAC parser self; on the other side
+# we could use the rdf:bagID reification (mess) to "automatically" associate a context to a group of statements (perhaps removing the useless high order statements)
+my $now='now'.time;
+my $p=new RDFStore::Parser::SiRPAC(
+ Style => 'RDFStore::Parser::Styles::RDFStore::Model',
+ NodeFactory => $factory,
+ style_options => { store_options => { FreeText => 1, Context => $factory->createResource($now) } }
+ );
+my $model = $p->parsefile("file:t/rdql-tests/rdf/lastampaEconomia.rdf");
+
+ok $tt++, $dbh= DBI->connect("DBI:RDFStore:", "root", 0, { sourceModel => $model } );
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?link
+WHERE
+(?x, <rdf:type>, <rss:item>, <$now>),
+(?x, <rss::title>, ?title, <$now>),
+(?x, <rss::link>, ?link, <$now>)
+AND ?title LIKE /incombe/i
+USING
+rss for <http://purl.org/rss/1.0/>,
+rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ die
+ unless(scalar(@row)>0);
+ map { print $_->toString,"\n" } @row
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (1 == $kk);
+ok $tt++, $query->finish();
+
+# a different context
+my $context='urn:rdf:magic:context:12345_ertoiororr';
+my $rdf_parser=new RDFStore::Parser::SiRPAC(
+ Style => 'RDFStore::Parser::Styles::RDFStore::Model',
+ NodeFactory => $factory,
+ style_options => { store_options => { FreeText => 1, Context => $factory->createResource($context) } }
+ );
+$model = $rdf_parser->parsefile("file:t/rdql-tests/rdf/lastampaEconomia.rdf");
+
+ok $tt++, $dbh= DBI->connect("DBI:RDFStore:", "root", 0, { sourceModel => $model } );
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?link
+WHERE
+(?x, <rdf:type>, <rss:item>, <$context>),
+(?x, <rss::title>, ?title, <$context>),
+(?x, <rss::link>, ?link, <$context>)
+AND ?title LIKE /incombe/i
+USING
+rss for <http://purl.org/rss/1.0/>,
+rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) {
+ die
+ unless(scalar(@row)>0);
+ map { print $_->toString,"\n" } @row
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (1 == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?x
+WHERE
+(?x, ?y, ?z, <$context>)
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) { $kk++; };
+};
+ok $tt++, !$@;
+ok $tt++, ($model->size == $kk);
+ok $tt++, $query->finish();
+
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?x
+WHERE
+(?x, <rdf:type>, ?y, <$context>)
+USING
+rss for <http://purl.org/rss/1.0/>,
+rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+QUERY
+ok $tt++, $query->execute();
+$kk=0;
+eval {
+while (my @row = $query->fetchrow_array()) { $kk++; };
+};
+ok $tt++, !$@;
+ok $tt++, (21 == $kk);
+ok $tt++, $query->finish();
+
+#remote queries
+if(0){
+ok $tt++, $query = $dbh->prepare(<<QUERY);
+SELECT ?title, ?link
+FROM <rdfstore://myremotedb_of_rss\@localhost:1234>
+WHERE
+ (?item, <rdf:type>, <rss:item>),
+ (?item, <rss::title>, ?title),
+ (?item, <rss::link>, ?link)
+USING
+ rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
+ rss for <http://purl.org/rss/1.0/>
+QUERY
+ok $tt++, $query->execute();
+ok $tt++, $query->bind_columns(\$title, \$link);
+$kk=0;
+eval {
+while ($query->fetch()) {
+ print "title=",$title->toString," link=".$link->toString,"\n"
+ if($::debug);
+ $kk++;
+ };
+};
+ok $tt++, !$@;
+ok $tt++, (8 == $kk);
+ok $tt++, $query->finish();
+};