Exemple #1
0
 public static void FillDatabaseFromTripletFlowVirtuoso(EntitiesAndTripletFlow lfd)
 {
     int bufferportion = 200;
     BufferredProcessing<Triplet> b_entities = new BufferredProcessing<Triplet>(bufferportion, flow =>
     {
         string command = "SPARQL INSERT INTO GRAPH <" + graph + "> {" +
             flow.Select(ent => "<" + ent.s + "> <" + ent.p + "> " +
                 ((ent is OProp) ?  "<" + ((OProp)ent).o + ">" : "\"" +
                     ((DProp)ent).d.Replace('\"', '\'').Replace('\\', '/').Replace('\n', ' ') +
                     (((DProp)ent).lang != null?"@"+((DProp)ent).lang:"") + "\"")
                 + ".")
             .Aggregate((sum, s) => sum + " " + s) + "}\n";
         RunCommand(command);
     });
     // Просканируем поток триплетов и вставим информацию в базу данных
     foreach (var tr in lfd.ScanDatabases())
     {
         b_entities.Add(tr);
     }
     b_entities.Flush();
 }
Exemple #2
0
 public static void FillDatabaseFromTripletFlow(EntitiesAndTripletFlow lfd)
 {
     int bufferportion = 200;
     BufferredProcessing<RDFEntity> b_entities = new BufferredProcessing<RDFEntity>(bufferportion, flow =>
     {
         string command = "INSERT INTO rdf_entities VALUES " +
             flow.Select(ent => "(" + ent.entityid + "," + ent.entitytype + ",'" + ent.entityvalue + "')")
             .Aggregate((sum, s) => sum + "," + s);
         RunCommand(command);
     });
     BufferredProcessing<RDFLiteral> b_literals = new BufferredProcessing<RDFLiteral>(bufferportion, flow =>
     {
         string command = "INSERT INTO rdf_literals VALUES " +
             flow.Select(lit => "(" + lit.literalid + ",N'" + lit.literalvalue.Replace('\'', '"') + "'," + (lit.literallang == null ? "NULL" : "'" + lit.literallang + "'") + ")")
             .Aggregate((sum, s) => sum + "," + s);
         RunCommand(command);
     });
     BufferredProcessing<RDFDStatement> b_dstatements = new BufferredProcessing<RDFDStatement>(bufferportion, flow =>
     {
         string command = "INSERT INTO rdf_dstatements VALUES " +
             flow.Select(dst => "(" + dst.dsubject + "," + dst.dpredicate + "," + dst.data + ")")
             .Aggregate((sum, s) => sum + "," + s);
         RunCommand(command);
     });
     BufferredProcessing<RDFOStatement> b_ostatements = new BufferredProcessing<RDFOStatement>(bufferportion, flow =>
     {
         string command = "INSERT INTO rdf_ostatements VALUES " +
             flow.Select(ost => "(" + ost.osubject + "," + ost.opredicate + "," + ost.oobj + ")")
             .Aggregate((sum, s) => sum + "," + s);
         RunCommand(command);
     });
     // Теперь просканируем поток триплетов и вставим информацию в базу данных
     foreach (var tr in lfd.ScanDatabases())
     {
         if (tr is OProp)
         {
             OProp op = (OProp)tr;
             int subj_i;
             if (lfd.TryGetEntity(op.s, out subj_i))
             {
                 int type_i = -1; string type_s = lfd.GetTypeOfEntity(op.s);
                 if (type_s != null && lfd.TryGetEntity(type_s, out type_i)) b_entities.Add(new RDFEntity() { entityid = type_i, entityvalue = type_s });
                 b_entities.Add(new RDFEntity() { entityid = subj_i, entitytype = type_i, entityvalue = op.s });
             }
             int pred_i;
             if (lfd.TryGetEntity(op.p, out pred_i)) b_entities.Add(new RDFEntity() { entityid = pred_i, entitytype = -1, entityvalue = op.p });
             int obj_i;
             if (lfd.TryGetEntity(op.o, out obj_i))
             {
                 int type_i = -1; string type_s = lfd.GetTypeOfEntity(op.o);
                 if (type_s != null && lfd.TryGetEntity(type_s, out type_i)) b_entities.Add(new RDFEntity() { entityid = type_i, entityvalue = type_s });
                 b_entities.Add(new RDFEntity() { entityid = obj_i, entitytype = type_i, entityvalue = op.o });
             }
             b_ostatements.Add(new RDFOStatement() { osubject = subj_i, opredicate = pred_i, oobj = obj_i });
         }
         else
         {
             DProp dp = (DProp)tr;
             int lit_i;
             if (lfd.TryGetLiteral(dp.d, out lit_i, dp.lang)) b_literals.Add(new RDFLiteral() { literalid = lit_i, literalvalue = dp.d, literallang = dp.lang });
             int subj_i;
             if (lfd.TryGetEntity(dp.s, out subj_i))
             {
                 int type_i = -1; string type_s = lfd.GetTypeOfEntity(dp.s);
                 if (type_s != null && lfd.TryGetEntity(type_s, out type_i)) b_entities.Add(new RDFEntity() { entityid = type_i, entityvalue = type_s });
                 b_entities.Add(new RDFEntity() { entityid = subj_i, entitytype = type_i, entityvalue = dp.s });
             }
             int pred_i;
             if (lfd.TryGetEntity(dp.p, out pred_i)) b_entities.Add(new RDFEntity() { entityid = pred_i, entitytype = -2, entityvalue = dp.p });
             b_dstatements.Add(new RDFDStatement() { dsubject = subj_i, dpredicate = pred_i, data = lit_i });
         }
     }
     b_entities.Flush();
     b_literals.Flush();
     b_dstatements.Flush();
     b_ostatements.Flush();
 }