Beispiel #1
0
  /**
   * Can be used to substitute the predicate of all the triplets with a specific predicate.
   *
   * <p>------------------------------------------------------------------- IMPORTANT: If modified,
   * this documentation must also be modified in the class GActionType.
   * -------------------------------------------------------------------
   *
   * <p>parameters expected:
   *
   * <ul>
   *   <li>old_uri: the URI predicate to replace
   *   <li>new_uri: the new URI predicate
   * </ul>
   *
   * You can use RDFS.SUBCLASSOF to refer to http://www.w3.org/2000/01/rdf-schema#subClassOf
   *
   * @param factory
   * @param action
   * @param g
   * @throws SLIB_Ex_Critic
   */
  private static void predicateSubstitution(URIFactory factory, GAction action, G g)
      throws SLIB_Ex_Critic {

    logger.info("-------------------------------------");
    logger.info(" Predicate Substitution");
    logger.info("-------------------------------------");
    logger.info("Starting " + GActionType.PREDICATE_SUBSTITUTE);

    String old_URI = (String) action.getParameter("old_uri");
    String new_URI = (String) action.getParameter("new_uri");

    if (old_URI == null || new_URI == null) {
      throw new SLIB_Ex_Critic("Error - please specify a parameter old_uri and new_uri");
    }

    if (old_URI.toUpperCase().equals("RDFS.SUBCLASSOF")) {
      old_URI = RDFS.SUBCLASSOF.toString();
    }
    if (new_URI.toUpperCase().equals("RDFS.SUBCLASSOF")) {
      new_URI = RDFS.SUBCLASSOF.toString();
    }

    URI oldURI = factory.getURI(old_URI);
    URI newURI = factory.getURI(new_URI);

    Set<E> oldRel = g.getE(oldURI);
    g.removeE(oldRel);

    for (E e : oldRel) {
      g.addE(e.getSource(), newURI, e.getTarget());
    }

    logger.info(oldRel.size() + " relations modified");
  }
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/bootstrap.xml"})
public class PublishServiceTestCase extends TestCase {

  @Autowired
  @Qualifier("system_fact")
  private Properties systemProps;

  @Autowired private PublishService service;
  @Autowired private AGraphDao dao;

  private static final String RAW_STR_1 =
      "<http://www.test.org/devGraph2><http://www.test.org/testClass1><"
          + RDFS.SUBCLASSOF.toString()
          + "><http://www.test.org/testClass2>";
  private static final String RAW_STR_2 =
      "<http://www.test.org/devGraph2><http://www.test.org/testInstance1><?p><http://www.test.org/testClass1>";
  private static final String RAW_STR_TOTAL = RAW_STR_1 + "," + RAW_STR_2;
  private static final String MOCK_UUID = "mark4";
  private String strToPub = "";

  @Before
  public void prepare() {
    this.strToPub =
        RAW_STR_TOTAL.replace(
            "?p", systemProps.getProperty("agraph.server.graph.subscribe.predicate"));
  }

  //	@Test
  //	public void testDoPublishWithoutNotification() throws ServiceException,
  // AGraphDataAccessException, ParameterException {
  //		service.doPublish(strToPub, MOCK_UUID, false, false);
  //
  //		List<String> superClass = this.dao.getImmediateClass(
  //				new IRI("<http://www.test.org/testClass1>", MOCK_UUID),
  //				"http://www.test.org/devGraph2",
  //				MOCK_UUID);
  //		assertNotNull(superClass);
  //		assertEquals(1, superClass.size());
  //		assertEquals("http://www.test.org/testClass2", superClass.get(0));
  //
  //		List<String> subscribers = this.dao.getSubscriberIRI("http://www.test.org/testClass1",
  // MOCK_UUID);
  //		assertNotNull(subscribers);
  //		assertEquals(1, subscribers.size());
  //		assertEquals("http://www.test.org/testInstance1", subscribers.get(0));
  //	}

  @After
  public void cleanup() throws ParameterException, AGraphDataAccessException {
    List<Quad> quads = new ArrayList<Quad>();
    quads.add(new Quad(RAW_STR_1, MOCK_UUID));
    quads.add(
        new Quad(
            RAW_STR_2.replace(
                "?p", systemProps.getProperty("agraph.server.graph.subscribe.predicate")),
            MOCK_UUID));
    this.dao.removeQuads(quads, MOCK_UUID, false);
  }
}
 /**
  * Asynchronously explains why class {@code cl} is unsatisfiable
  *
  * @param cl The class to check for unsatisfiability
  * @param callback The {@link Callback} to execute after the explanation is done
  */
 public void unsat(Resource cl, Callback<Graph> callback) {
   String query =
       selectQuery(
           cl.stringValue(),
           RDFS.SUBCLASSOF.stringValue(),
           "http://www.w3.org/2002/07/owl#Nothing");
   query(query, callback);
 }
 /**
  * Explains why class {@code cl} is unsatisfiable
  *
  * @param cl The class to check for unsatisfiability
  * @return The explanation {@link org.openrdf.model.Graph Graph}
  * @throws PelletClientException If there is an error or {@code cl} is not unsatisfiable
  */
 public Graph unsat(Resource cl) throws PelletClientException {
   String query =
       selectQuery(
           cl.stringValue(),
           RDFS.SUBCLASSOF.stringValue(),
           "http://www.w3.org/2002/07/owl#Nothing");
   return query(query);
 }
 /**
  * Explains why {@code subclass} is rdfs:subclassOf {@code superclass}
  *
  * @param subclass The sub class
  * @param superclass The super class
  * @return The explanation {@link org.openrdf.model.Graph Graph}
  * @throws PelletClientException if there is an error while querying
  */
 public Graph subclass(Resource subclass, Resource superclass) throws PelletClientException {
   String query =
       selectQuery(
           subclass.stringValue(), RDFS.SUBCLASSOF.stringValue(), superclass.stringValue());
   return query(query);
 }
 /**
  * Asynchronously explains why {@code subclass} is rdfs:subclassOf {@code superclass}
  *
  * @param subclass The sub class
  * @param superclass The super class
  * @param callback The {@link Callback} to execute after the explanation is done
  */
 public void subclass(Resource subclass, Resource superclass, Callback<Graph> callback) {
   String query =
       selectQuery(
           subclass.stringValue(), RDFS.SUBCLASSOF.stringValue(), superclass.stringValue());
   query(query, callback);
 }