Пример #1
0
  /**
   * Fills the cache c with the data contained in the data source described by kb
   *
   * @param c The cache to be filled
   */
  public void fillCache(ACache c) {
    Logger logger = LoggerFactory.getLogger("LIMES");
    try {

      // in case a CSV is used, endpoint is the file to read
      BufferedReader reader = new BufferedReader(new FileReader(kb.getEndpoint()));
      logger.info("Reading vectors from " + kb.getEndpoint());
      String s = reader.readLine();
      String uri;

      // read properties. Vectors are assumed to have only one property,
      // which is that used by the user to in the description of the similarity
      // to be used. In general, we assume that vectors can only be compared
      // with other vectors.

      ArrayList<String> properties = new ArrayList<String>();
      properties.add(kb.getProperties().get(0));
      while (s != null) {
        if (s.contains(SEP)) {
          uri = s.substring(1, s.indexOf(SEP) - 1);
          c.addTriple(uri, properties.get(0), s.substring(s.indexOf(SEP)));
        }
        s = reader.readLine();
      }
      reader.close();
      logger.info("Retrieved " + c.size() + " statements");
    } catch (Exception e) {
      logger.error(MarkerFactory.getMarker("FATAL"), "Exception:" + e.getMessage());
      e.printStackTrace();
    }
  }
Пример #2
0
 private List<Set<String>> buildIndex(ACache c, String p) {
   List<Set<String>> index = new ArrayList<>();
   // Phase 1: Build index
   for (String uri : c.getAllUris()) {
     Set<String> values = new NamedHashSet<>(c.getInstance(uri).getProperty(p), uri);
     if (values.size() > 0) {
       index.add(values);
     }
   }
   SetSizeQuicksort.sort(index);
   return index;
 }
Пример #3
0
 @Test
 public void begin() {
   Set<String> dates = new TreeSet<String>();
   for (Instance s : source.getAllInstances()) {
     String d = s.getProperty("beginsAtDateTime").first();
     if (!dates.contains(d)) dates.add(d);
     String e = s.getProperty("endsAtDateTime").first();
     if (!dates.contains(e)) dates.add(e);
   }
   for (String s : dates) {
     System.out.println(s);
   }
 }
Пример #4
0
  @Test
  public void similarity() {
    System.out.println("similarity");
    LinkSpecification ls =
        new LinkSpecification(
            "tmp_is_started_by(x.beginsAtDateTime|endsAtDateTime,y.beginsAtDateTime|endsAtDateTime)",
            1.0);
    DynamicPlanner p = new DynamicPlanner(source, target);
    ExecutionEngine e = new SimpleExecutionEngine(source, target, "?x", "?y");
    AMapping m = e.execute(ls, p);
    System.out.println(m);

    AMapping m2 = MappingFactory.createDefaultMapping();
    for (Instance s : source.getAllInstances()) {
      for (Instance t : target.getAllInstances()) {
        IsStartedByMeasure measure = new IsStartedByMeasure();
        double sim =
            measure.getSimilarity(
                s, t, "beginsAtDateTime|endsAtDateTime", "beginsAtDateTime|endsAtDateTime");
        if (sim != 0) m2.add(s.getUri(), t.getUri(), sim);
      }
    }
    assertTrue(m.equals(m2));
  }
Пример #5
0
  @Before
  public void setUp() {
    source = new MemoryCache();
    target = new MemoryCache();
    // create source cache
    source.addTriple("S1", "surname", "georgala");
    source.addTriple("S1", "name", "kleanthi");
    source.addTriple("S1", "age", "26");

    source.addTriple("S2", "surname", "sandra");
    source.addTriple("S2", "name", "lukas");
    source.addTriple("S2", "age", "13");

    source.addTriple("S3", "surname", "depp");
    source.addTriple("S3", "name", "johny");
    source.addTriple("S3", "age", "52");

    source.addTriple("S4", "surname", "swift");
    source.addTriple("S4", "name", "taylor,maria");
    source.addTriple("S4", "age", "25");

    source.addTriple("S5", "surname", "paok");
    source.addTriple("S5", "name", "ole");
    source.addTriple("S5", "age", "56");

    target.addTriple("T1", "surname", "georg");
    target.addTriple("T1", "name", "klea");
    target.addTriple("T1", "age", "26");

    target.addTriple("T2", "surname", "sandra");
    target.addTriple("T2", "name", "lukas");
    target.addTriple("T2", "age", "13");

    target.addTriple("T3", "surname", "derp");
    target.addTriple("T3", "name", "johnny");
    target.addTriple("T3", "age", "52");

    target.addTriple("T4", "surname", "swift");
    target.addTriple("T4", "name", "taylor");
    target.addTriple("T4", "age", "25");

    target.addTriple("T5", "surname", "paok");
    target.addTriple("T5", "name", "oleole");
    target.addTriple("T5", "age", "56");
  }
Пример #6
0
  @Before
  public void setUp() {
    source = new MemoryCache();
    target = new MemoryCache();
    // create source cache
    source.addTriple("S1", "beginsAtDateTime", "2015-05-20T08:21:04+02:00");
    source.addTriple("S1", "endsAtDateTime", "2015-05-20T08:22:04+02:00");

    source.addTriple("S2", "beginsAtDateTime", "2015-05-20T08:21:04+02:00");
    source.addTriple("S2", "endsAtDateTime", "2015-05-20T08:22:04+02:00");

    source.addTriple("S3", "beginsAtDateTime", "2015-05-20T08:24:04+02:00");
    source.addTriple("S3", "endsAtDateTime", "2015-05-20T08:25:04+02:00");

    source.addTriple("S4", "beginsAtDateTime", "2015-05-20T08:31:04+02:00");
    source.addTriple("S4", "endsAtDateTime", "2015-05-20T08:32:04+02:00");

    source.addTriple("S5", "beginsAtDateTime", "2015-05-20T09:21:04+02:00");
    source.addTriple("S5", "endsAtDateTime", "2015-05-20T09:24:04+02:00");

    source.addTriple("S6", "beginsAtDateTime", "2015-05-20T08:51:04+02:00");
    source.addTriple("S6", "endsAtDateTime", "2015-05-20T09:24:04+02:00");

    source.addTriple("S7", "beginsAtDateTime", "2015-05-20T08:41:04+02:00");
    source.addTriple("S7", "endsAtDateTime", "2015-05-20T08:51:04+02:00");

    source.addTriple("S8", "beginsAtDateTime", "2015-05-20T08:41:04+02:00");
    source.addTriple("S8", "endsAtDateTime", "2015-05-20T08:43:04+02:00");

    source.addTriple("S9", "beginsAtDateTime", "2015-05-20T08:21:04+02:00");
    source.addTriple("S9", "endsAtDateTime", "2015-05-20T08:34:04+02:00");

    source.addTriple("S10", "beginsAtDateTime", "2015-05-20T09:21:04+02:00");
    source.addTriple("S10", "endsAtDateTime", "2015-05-20T09:22:04+02:00");

    source.addTriple("S11", "beginsAtDateTime", "2015-05-20T09:21:04+02:00");
    source.addTriple("S11", "endsAtDateTime", "2015-05-20T09:22:04+02:00");

    source.addTriple("S12", "beginsAtDateTime", "2015-05-20T08:31:04+02:00");
    source.addTriple("S12", "endsAtDateTime", "2015-05-20T08:45:04+02:00");

    target = source;
  }