예제 #1
0
  public static Offering convertOffering(Resource resource, Float price) {
    Offering offering = new Offering();

    offering.setId(resource.getLocalName());
    if (resource.hasProperty(label)) {
      offering.setName(resource.getProperty(label).getString());
    } else {
      offering.setName(resource.getLocalName());
    }

    if (resource.hasProperty(comment)) {
      offering.setDescription(resource.getProperty(comment).getString());
    }

    // get included services
    StmtIterator iter = resource.listProperties(includes);
    // System.out.println(iter.toList().size());
    while (iter.hasNext()) {
      Resource service = iter.next().getResource();
      offering = addFeatures(service, offering);
    }

    // get offering price
    offering = getOfferingPrice(price, offering);

    return offering;
  }
  private static void extractList(List<String> output, Resource head) {
    if (head.hasProperty(RDF.first))
      output.add(head.getProperty(RDF.first).getObject().asLiteral().getString());

    if (head.hasProperty(RDF.rest))
      extractList(output, head.getProperty(RDF.rest).getObject().asResource());
  }
예제 #3
0
  private static QualitativeFeature convertQualitativeFeature(Resource r, String attributeType) {
    QualitativeFeature qf = new QualitativeFeature();
    qf.setType(QUAL_FEATURE.get(attributeType));
    if (r.hasProperty(comment)) qf.setDescription(r.getProperty(comment).getString());
    if (r.hasProperty(name)) qf.setName(r.getProperty(name).getString());

    return qf;
  }
 @Test
 public void testSave() throws BadRequestException {
   folderResourceMap.save();
   Model model = ModelFactory.createDefaultModel();
   model.read(folderResourceMap.getGraphAsInputStream(RDFFormat.RDFXML), null);
   Resource r = model.getResource(folderResourceMap.getUri().toString());
   Assert.assertTrue(r.hasProperty(ORE.describes, model.getResource(folder.getUri().toString())));
   Assert.assertTrue(r.hasProperty(RDF.type, ORE.ResourceMap));
 }
예제 #5
0
 public static String getVocabularyTitle(Model vocabulary, String uri) {
   Resource nsResource = vocabulary.createResource(uri);
   if (nsResource.hasProperty(DCTerms.title)) {
     return nsResource.getProperty(DCTerms.title).getString();
   } else if (nsResource.hasProperty(DC.title)) {
     return nsResource.getProperty(DC.title).getString();
   } else if (nsResource.hasProperty(RDFS.label))
     return nsResource.getProperty(RDFS.label).getString();
   return null;
 }
예제 #6
0
  private static QuantitativeFeature convertQuantitativeFeature(Resource r, String attributeType) {
    QuantitativeFeature qf = new QuantitativeFeature();
    qf.setName(r.getLocalName());
    qf.setType(QUANT_FEATURE.get(attributeType));
    if (r.hasProperty(comment)) qf.setDescription(r.getProperty(comment).getString());
    if (r.hasProperty(hasValue)) qf.setValueFloat(r.getProperty(hasValue).getFloat());
    if (r.hasProperty(hasUnitOfMeasurement))
      qf.setUnitOfMeasurement(
          UNIT_OF_MEASUREMENT.get(r.getProperty(hasUnitOfMeasurement).getString()));

    return qf;
  }
예제 #7
0
 DeviceData(Resource device) {
   this.device = device;
   if (device.hasProperty(DeliSchema.manufacturedBy)) {
     if (device.getProperty(DeliSchema.manufacturedBy).getResource().hasProperty(RDFS.label)) {
       this.manufacturerName =
           device
               .getProperty(DeliSchema.manufacturedBy)
               .getResource()
               .getProperty(RDFS.label)
               .getString();
     }
   }
   if (device.hasProperty(DeliSchema.deviceName)) {
     this.deviceName = device.getProperty(DeliSchema.deviceName).getString();
   }
 }
예제 #8
0
 @Test
 public void testPresentTotalCount() throws URISyntaxException {
   Integer totalResults = new Integer(17);
   Resource thisMetaPage = createMetadata(true, totalResults);
   Literal tr = thisMetaPage.getModel().createTypedLiteral(totalResults);
   assertTrue(thisMetaPage.hasProperty(OpenSearch.totalResults, tr));
 }
예제 #9
0
 public MappedResource getIndexResource() {
   if (!config.hasProperty(CONF.indexResource)) {
     return null;
   }
   return getMappedResourceFromDatasetURI(
       config.getProperty(CONF.indexResource).getResource().getURI());
 }
예제 #10
0
  public Configuration(Model configurationModel) {
    model = configurationModel;
    StmtIterator it = model.listStatements(null, RDF.type, CONF.Configuration);
    if (!it.hasNext()) {
      throw new IllegalArgumentException("No conf:Configuration found in configuration model");
    }
    config = it.nextStatement().getSubject();

    datasets = new ArrayList();
    it = model.listStatements(config, CONF.dataset, (RDFNode) null);
    while (it.hasNext()) {
      datasets.add(new Dataset(it.nextStatement().getResource()));
    }
    labelProperties = new ArrayList();
    it = model.listStatements(config, CONF.labelProperty, (RDFNode) null);
    while (it.hasNext()) {
      labelProperties.add(it.nextStatement().getObject().as(Property.class));
    }
    if (labelProperties.isEmpty()) {
      labelProperties.add(RDFS.label);
      labelProperties.add(DC.title);
      labelProperties.add(model.createProperty("http://xmlns.com/foaf/0.1/name"));
    }
    commentProperties = new ArrayList();
    it = model.listStatements(config, CONF.commentProperty, (RDFNode) null);
    while (it.hasNext()) {
      commentProperties.add(it.nextStatement().getObject().as(Property.class));
    }
    if (commentProperties.isEmpty()) {
      commentProperties.add(RDFS.comment);
      commentProperties.add(DC.description);
    }
    imageProperties = new ArrayList();
    it = model.listStatements(config, CONF.imageProperty, (RDFNode) null);
    while (it.hasNext()) {
      imageProperties.add(it.nextStatement().getObject().as(Property.class));
    }
    if (imageProperties.isEmpty()) {
      imageProperties.add(model.createProperty("http://xmlns.com/foaf/0.1/depiction"));
    }

    prefixes = new PrefixMappingImpl();
    if (config.hasProperty(CONF.usePrefixesFrom)) {
      it = config.listProperties(CONF.usePrefixesFrom);
      while (it.hasNext()) {
        Statement stmt = it.nextStatement();
        prefixes.setNsPrefixes(FileManager.get().loadModel(stmt.getResource().getURI()));
      }
    } else {
      prefixes.setNsPrefixes(model);
    }
    if (prefixes.getNsURIPrefix(CONF.NS) != null) {
      prefixes.removeNsPrefix(prefixes.getNsURIPrefix(CONF.NS));
    }
  }
 @Test
 public void testSaveFolderEntryData() throws BadRequestException {
   InputStream is =
       getClass().getClassLoader().getResourceAsStream(FolderBuilder.DEFAULT_FOLDER_PATH);
   researchObject.aggregate("new-resource", is, "text/plain");
   is =
       getClass()
           .getClassLoader()
           .getResourceAsStream("model/ro/folder_resource_map/folder_entry.rdf");
   FolderEntry fe = folder.createFolderEntry(is);
   folderResourceMap.saveFolderEntryData(fe);
   Model model = ModelFactory.createDefaultModel();
   model.read(folderResourceMap.getGraphAsInputStream(RDFFormat.RDFXML), null);
   Resource r = model.getResource(fe.getUri().toString());
   Assert.assertTrue(r.hasProperty(RDF.type, RO.FolderEntry));
   r = model.getResource(fe.getProxyFor().getUri().toString());
   Assert.assertTrue(
       r.hasProperty(ORE.isAggregatedBy, model.getResource(fe.getProxyIn().getUri().toString())));
   r = model.getResource(fe.getProxyIn().getUri().toString());
   Assert.assertTrue(
       r.hasProperty(ORE.aggregates, model.getResource(fe.getProxyFor().getUri().toString())));
 }
예제 #12
0
 /**
  * @see org.caboto.jena.db.Database#updateProperty(java.lang.String, java.lang.String,
  *     com.hp.hpl.jena.rdf.model.Property, com.hp.hpl.jena.rdf.model.RDFNode)
  */
 public boolean updateProperty(String uri, String resourceUri, Property property, RDFNode value) {
   try {
     log.info("Updting property in model: " + uri + " " + reasoner);
     Data data = getData();
     Model m = data.getModel(uri);
     if (!m.containsResource(ResourceFactory.createResource(resourceUri))) {
       m.close();
       data.close();
       return false;
     }
     Resource resource = m.getResource(resourceUri);
     if (resource.hasProperty(property)) {
       resource.getProperty(property).changeObject(value);
     } else {
       resource.addProperty(property, value);
     }
     m.close();
     data.close();
     return true;
   } catch (DataException e) {
     e.printStackTrace();
     return false;
   }
 }
예제 #13
0
  /**
   * Checks if a given RDFNode represents a template call. It either needs to be an instance of an
   * instance of sh:Template, or be a typeless blank node that has an incoming edge via a property
   * such as sh:property, that has a declared sh:defaultType.
   *
   * @param node the node to check
   * @return true if node is a template call
   */
  public static boolean isTemplateCall(RDFNode node) {
    if (node != null && node.isResource()) {
      Resource resource = (Resource) node;

      // Return true if this has sh:Template as its metaclass
      for (Resource type : JenaUtil.getTypes(resource)) {
        if (JenaUtil.hasIndirectType(type, SH.Template)) {
          return true;
        }
      }

      // If this is a typeless blank node, check for defaultType of incoming references
      if (resource.isAnon() && !resource.hasProperty(RDF.type)) {
        Resource dt = SHACLUtil.getDefaultTemplateType(resource);
        if (dt != null
            && !SH.NativeConstraint.equals(dt)
            && !SH.NativeScope.equals(dt)
            && !SH.NativeRule.equals(dt)) {
          return true;
        }
      }
    }
    return false;
  }
예제 #14
0
 @Test
 public void testAbsentTotalCount() throws URISyntaxException {
   Integer totalResults = null;
   Resource thisMetaPage = createMetadata(true, totalResults);
   assertFalse(thisMetaPage.hasProperty(OpenSearch.totalResults));
 }
 /**
  * @see com.hp.hpl.jena.rdf.model.Resource#hasProperty(com.hp.hpl.jena.rdf.model.Property,
  *     java.lang.String, java.lang.String)
  */
 public boolean hasProperty(Property p, String o, String l) {
   synchronized (model) {
     return wrapped.hasProperty(p, o, l);
   }
 }
예제 #16
0
 @Test
 public void testItemEndpointHasCorrectType() throws URISyntaxException {
   Integer totalResults = null;
   Resource thisMetaPage = createMetadata(false, totalResults);
   assertTrue(thisMetaPage.hasProperty(RDF.type, API.ItemEndpoint));
 }
예제 #17
0
 protected void checkType(Resource root, Resource type) {
   if (!root.hasProperty(RDF.type, type))
     throw new CannotConstructException(this.getClass(), root, type);
 }
예제 #18
0
 public String getDefaultLanguage() {
   if (!config.hasProperty(CONF.defaultLanguage)) {
     return null;
   }
   return config.getProperty(CONF.defaultLanguage).getString();
 }
예제 #19
0
 boolean hasRelease() {
   return device.hasProperty(DeliSchema.release);
 }
예제 #20
0
 boolean hasProvider() {
   return device.hasProperty(DeliSchema.provider);
 }
 /**
  * @see com.hp.hpl.jena.rdf.model.Resource#hasProperty(com.hp.hpl.jena.rdf.model.Property,
  *     com.hp.hpl.jena.rdf.model.RDFNode)
  */
 public boolean hasProperty(Property p, RDFNode o) {
   synchronized (model) {
     return wrapped.hasProperty(p, o);
   }
 }
예제 #22
0
 private static void removeElementsWithoutType(Set<Resource> candidates, Resource type) {
   for (Iterator<Resource> it = candidates.iterator(); it.hasNext(); ) {
     Resource candidate = it.next();
     if (!candidate.hasProperty(RDF.type, type)) it.remove();
   }
 }
 /** @see com.hp.hpl.jena.rdf.model.Resource#hasProperty(com.hp.hpl.jena.rdf.model.Property) */
 public boolean hasProperty(Property p) {
   synchronized (model) {
     return wrapped.hasProperty(p);
   }
 }