Exemplo n.º 1
0
static void insert_quad(xmlctxt *ctxt)
{
  fs_rid buffer[1][4];
  int subj = FS_RID_SEGMENT(ctxt->s, ctxt->segments);
  int obj = FS_RID_SEGMENT(ctxt->o, ctxt->segments);

  buffer[0][0] = ctxt->m;
  buffer[0][1] = ctxt->s;
  buffer[0][2] = ctxt->p;
  buffer[0][3] = ctxt->o;

  fsp_quad_import(ctxt->link, subj, FS_BIND_BY_SUBJECT, 1, buffer);
  fsp_quad_import(ctxt->link, obj, FS_BIND_BY_OBJECT, 1, buffer);
}
Exemplo n.º 2
0
static int flush_triples(struct update_context *uc)
{
    for (int s=0; s<uc->segments; s++) {
        if (quad_buffer[s].length > 0) {
            fsp_quad_import(uc->link, s, FS_BIND_BY_SUBJECT, quad_buffer[s].length, quad_buffer[s].quads);
            quad_buffer[s].length = 0;
        }
    }

    return 0;
}
Exemplo n.º 3
0
static int insert_rasqal_triple(struct update_context *uc, rasqal_triple *triple, int row)
{
    fs_rid quad_buf[1][4];
    fs_resource res;
    if (triple->origin) {
        fs_resource_from_rasqal_literal(uc, triple->origin, &res, row);
        quad_buf[0][0] = fs_hash_rasqal_literal(uc, triple->origin, row);
    } else if (uc->op->graph_uri) {
        res.lex = (char *)raptor_uri_as_string(uc->op->graph_uri);
        res.attr = FS_RID_NULL;
        quad_buf[0][0] =
            fs_hash_uri((char *)raptor_uri_as_string(uc->op->graph_uri));
    } else {
        quad_buf[0][0] = fs_c.default_graph;
        res.lex = FS_DEFAULT_GRAPH;
        res.attr = FS_RID_NULL;
    }

    if (quad_buf[0][0] == fs_c.system_config)
        fsp_reload_acl_system(uc->link);

    if (!FS_IS_URI(quad_buf[0][0])) {
        return 1;
    }
    quad_buf[0][1] = fs_hash_rasqal_literal(uc, triple->subject, row);
    if (FS_IS_LITERAL(quad_buf[0][1])) {
        return 1;
    }
    quad_buf[0][2] = fs_hash_rasqal_literal(uc, triple->predicate, row);
    if (!FS_IS_URI(quad_buf[0][2])) {
        return 1;
    }
    quad_buf[0][3] = fs_hash_rasqal_literal(uc, triple->object, row);
    res.rid = quad_buf[0][0];
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][0], uc->segments), 1, &res);
    res.rid = quad_buf[0][1];
    fs_resource_from_rasqal_literal(uc, triple->subject, &res, 0);
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][1], uc->segments), 1, &res);
    res.rid = quad_buf[0][2];
    fs_resource_from_rasqal_literal(uc, triple->predicate, &res, 0);
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][2], uc->segments), 1, &res);
    res.rid = quad_buf[0][3];
    fs_resource_from_rasqal_literal(uc, triple->object, &res, 0);
    if (res.lex) fsp_res_import(uc->link, FS_RID_SEGMENT(quad_buf[0][3], uc->segments), 1, &res);
    fsp_quad_import(uc->link, FS_RID_SEGMENT(quad_buf[0][1], uc->segments), FS_BIND_BY_SUBJECT, 1, quad_buf);
//printf("I %016llx %016llx %016llx %016llx\n", quad_buf[0][0], quad_buf[0][1], quad_buf[0][2], quad_buf[0][3]);

    return 0;
}
Exemplo n.º 4
0
/* insert the triples in s, p, o into model */
static int insert_triples(struct update_context *uc, fs_rid model, fs_rid_vector *s, fs_rid_vector *p, fs_rid_vector *o)
{
    for (int i=0; i<s->length; i++) {
        int segment = FS_RID_SEGMENT(s->data[i], uc->segments);
        int pos = quad_buffer[segment].length;
        quad_buffer[segment].quads[pos][0] = model;
        quad_buffer[segment].quads[pos][1] = s->data[i];
        quad_buffer[segment].quads[pos][2] = p->data[i];
        quad_buffer[segment].quads[pos][3] = o->data[i];
        quad_buffer[segment].length++;
        if (quad_buffer[segment].length == QUAD_BUF_SIZE) {
            fsp_quad_import(uc->link, segment, FS_BIND_BY_SUBJECT, quad_buffer[segment].length, quad_buffer[segment].quads);
            quad_buffer[segment].length = 0;
        }
    }
    flush_triples(uc);
    //if (model == fs
    printf("%p ",uc->link->kb_name); 
    return 0;
}
Exemplo n.º 5
0
static int process_quads(fs_parse_stuff *data)
{
    fsp_link *link = data->link;
    const int segments = data->segments;
    int tfd = data->quad_fd;
    int verbosity = data->verbosity;
    int dryrun = data->dryrun;
    int total = 0;
    int ret;
    struct timeval now;

    if (lseek(tfd, 0, SEEK_SET) == -1) {
        fs_error(LOG_ERR, "error seeking in triple buffer file (fd %d): %s", tfd, strerror(errno));

        return -1;
    }
    do {
	ret = read(tfd, quad_buf, sizeof(quad_buf));
	int count = ret / (sizeof(fs_rid) * 4);
	if (ret < 0) {
	    fs_error(LOG_ERR, "error reading triple buffer file (fd %d): %s", tfd, strerror(errno));
	    return -1;
	}
	if (ret % sizeof(fs_rid) * 4 != 0) {
	    fs_error(LOG_ERR, "bad read size, %d - not multiple of 4 RIDs", ret);
	    return -1;
	}
	total += count;
	for (int seg=0; seg < segments; seg++) {
	    int i=0, scnt = 0;
	    for (i=0; i<count; i++) {
		if (FS_RID_SEGMENT(quad_buf[i][1], segments) == seg) {
		    quad_buf_s[scnt][0] = quad_buf[i][0];
		    quad_buf_s[scnt][1] = quad_buf[i][1];
		    quad_buf_s[scnt][2] = quad_buf[i][2];
		    quad_buf_s[scnt][3] = quad_buf[i][3];
		    scnt++;
		}
            }
	    if (!(dryrun & FS_DRYRUN_QUADS) && scnt > 0 && fsp_quad_import(link, seg, FS_BIND_BY_SUBJECT, scnt, quad_buf_s)) {
		fs_error(LOG_ERR, "quad import failed");

		return 1;
	    }
	}
	if (verbosity) printf("Pass 2, processed %d triples\r", total);
	fflush(stdout);
    } while (ret == sizeof(quad_buf));
    if (verbosity) {
        gettimeofday(&now, 0);
        double diff = (now.tv_sec - then_last.tv_sec) +
			(now.tv_usec - then_last.tv_usec) * 0.000001;
        printf("Pass 2, processed %d triples", total);
        if (total > 0) {
	    printf(", %d triples/s\n", (int)((double)total/diff));
        } else {
	    printf("\n");
        }
    }
    ftruncate(tfd, 0);
    lseek(tfd, 0, SEEK_SET);

    return total;
}