Пример #1
0
 /**
  * Called when a statement with literal value is added to the model.
  *
  * @param subject IRI of the subject resource
  * @param predicate IRI of the predicate resource
  * @param object literal object value
  * @param dataType the IRI of the literal's datatype (may be {@code null})
  * @param reificationID if not {@code null}, contains IRI of the resource that will wold the
  *     reified statement
  */
 public void statementWithLiteralValue(
     @Nonnull String subject,
     @Nonnull String predicate,
     @Nonnull String object,
     @Nullable String dataType,
     @Nullable String reificationID) {
   consumer.statementWithLiteralValue(subject, predicate, object, language, dataType);
   if (reificationID != null) {
     consumer.statementWithResourceValue(reificationID, RDF_TYPE, RDF_STATEMENT);
     consumer.statementWithResourceValue(reificationID, RDF_SUBJECT, subject);
     consumer.statementWithResourceValue(reificationID, RDF_PREDICATE, predicate);
     consumer.statementWithLiteralValue(reificationID, RDF_OBJECT, object, language, dataType);
   }
 }
Пример #2
0
  /**
   * Parses RDF from given input source.
   *
   * @param source specifies where RDF comes from
   * @param inputConsumer receives notifications about RDF parsing events
   * @throws SAXException SAXException
   * @throws IOException IOException
   */
  public void parse(@Nonnull InputSource source, @Nonnull RDFConsumer inputConsumer)
      throws SAXException, IOException {
    InputSource s = checkNotNull(source, "source cannot be null");
    checkNotNull(inputConsumer, "consumer cannot be null");
    String systemID = s.getSystemId();
    try {
      if (systemID != null) {
        baseIRI = IRI.create(new URI(source.getSystemId()));
      } else {
        throw new SAXException(
            "Supplied InputSource object myst have systemId property set, which is needed for IRI resolution.");
      }
      consumer = inputConsumer;
      inputConsumer.startModel(getBaseIRI());
      DeclHandler handler =
          new DeclHandler() {

            public void internalEntityDecl(String name, String value) {
              consumer.addPrefix(name, value);
            }

            public void externalEntityDecl(String name, String publicId, String systemId) {}

            public void elementDecl(String name, String model) {}

            public void attributeDecl(
                String eName, String aName, String type, String mode, String value) {}
          };
      SAXParsers.initParserWithOWLAPIStandards(handler).parse(source, this);
      inputConsumer.endModel();
    } catch (URISyntaxException e) {
      throw new SAXException("Invalid SystemID '" + systemID + "'of the supplied input source.", e);
    } finally {
      state = null;
      states.clear();
      baseIRIs.clear();
    }
  }
Пример #3
0
 @Override
 public void processingInstruction(String target, String data) {
   if ("include-rdf".equals(target)) {
     Map<String, String> arguments = parseStringArguments(data);
     verify(
         arguments.size() > 2,
         "Incorrect number of arguments for 'include-rdf' processing instruction.");
     String logicalIRI = arguments.get("logicalIRI");
     String physicalIRI = arguments.get("physicalIRI");
     if (physicalIRI != null) {
       physicalIRI = resolveIRI(physicalIRI);
     }
     consumer.includeModel(logicalIRI, physicalIRI);
   }
 }
Пример #4
0
 /**
  * Called when a statement with resource value is added to the model.
  *
  * @param subject IRI of the subject resource
  * @param predicate IRI of the predicate resource
  * @param object IRI of the object resource
  * @param reificationID if not {@code null}, contains IRI of the resource that will wold the
  *     reified statement
  */
 public void statementWithResourceValue(
     @Nonnull String subject,
     @Nonnull String predicate,
     @Nonnull String object,
     @Nullable String reificationID) {
   String remappedSubject = consumer.remapOnlyIfRemapped(subject);
   consumer.statementWithResourceValue(remappedSubject, predicate, object);
   if (reificationID != null) {
     consumer.statementWithResourceValue(reificationID, RDF_TYPE, RDF_STATEMENT);
     consumer.statementWithResourceValue(reificationID, RDF_SUBJECT, remappedSubject);
     consumer.statementWithResourceValue(reificationID, RDF_PREDICATE, predicate);
     consumer.statementWithResourceValue(reificationID, RDF_OBJECT, object);
   }
 }