Package org.openrdf.model

Examples of org.openrdf.model.ValueFactory


            model = new SailRepository(new MemoryStore());
            try{
              model.initialize();
              RepositoryConnection con = model.getConnection();
              try{
                ValueFactory factory = con.getValueFactory();
                blanks = new BNode[schema.get_blanks().size()];
                for (int i = 0; i < blanks.length; i++) {
                  blanks[i] = factory.createBNode();
                }
              }finally{
                con.close();
              }
            }catch(RepositoryException ex){
View Full Code Here


        try {
            RepositoryConnection conn = sesameService.getConnection();
            try {
                checkConnectionNamespace(conn);
                conn.begin();
                ValueFactory factory = conn.getValueFactory();
                URI resource = ResourceUtils.getUriResource(conn, uri);
                //TODO: chek if already exists
                conn.add(resource, RDF.TYPE, factory.createURI(prefixService.getNamespace("ldp"), "Resource"), container);
                conn.add(resource, factory.createURI(prefixService.getNamespace("dct"), "created"), factory.createLiteral(new Date()), container);
                conn.add(container, RDFS.MEMBER, resource, container);
                return true; //FIXME: 201 vs 200
            } finally {
                conn.commit();
                conn.close();
View Full Code Here

        try {
            RepositoryConnection conn = sesameService.getConnection();
            try {
                checkConnectionNamespace(conn);
                conn.begin();
                ValueFactory factory = conn.getValueFactory();
                URI uri = ResourceUtils.getUriResource(conn, container);
                conn.add(uri, RDF.TYPE, factory.createURI(prefixService.getNamespace("ldp"), "Container"), context);
                conn.add(uri, RDFS.LABEL, factory.createLiteral(title), context);
                conn.add(uri, factory.createURI(prefixService.getNamespace("dct"), "created"), factory.createLiteral(new Date()), context);
                log.info("Created new container <{}>", uri.stringValue());
                return true;
            } finally {
                conn.commit();
                conn.close();
View Full Code Here

        try {
            RepositoryConnection conn = sesameService.getConnection();
            try {
                conn.begin();
                checkConnectionNamespace(conn);
                ValueFactory valueFactory = conn.getValueFactory();
        URI ctx = valueFactory.createURI(uri);
                if (StringUtils.isNotBlank(label)) {
                    conn.add(ctx, RDFS.LABEL, Literals.createLiteral(valueFactory, label), ctx);
                }
                return ctx;
            } finally {
View Full Code Here

        try {
            Document htmlDoc = Jsoup.parse(in,charset,requestUrl);

            RepositoryConnection con = triples.getConnection();
            ValueFactory vf = con.getValueFactory();
            URI subject = vf.createURI(resource);

            for (Map.Entry<String, JSoupMapper> mapping : getMappings(resource, requestUrl).entrySet()) {
                URI predicate = vf.createURI(mapping.getKey());

                final Elements values = mapping.getValue().select(htmlDoc);
                for(Element value : values) {
                    List<Value> objects = mapping.getValue().map(resource, value, vf);
                    for(Value object : objects) {
                        Statement stmt = vf.createStatement(subject, predicate, object);
                        con.add(stmt);
                    }
                }
            }

            org.openrdf.model.URI ptype = vf.createURI(Namespaces.NS_RDF + "type");

            for(String typeUri : getTypes(subject)) {
                Resource type_resource = vf.createURI(typeUri);
                con.add(vf.createStatement(subject, ptype, type_resource));
            }

            con.commit();
            con.close();
View Full Code Here

            RepositoryConnection con = repository.getConnection();
            try {
                con.begin();

                ValueFactory vf = repository.getValueFactory();

                URI subject = vf.createURI(resourceUri);

                // add the type based on the facebook category
                if(data.get("category") != null) {
                    con.add(subject, RDF.TYPE, getType(data.get("category").toString()));
                }

                con.add(subject,DCTERMS.identifier,vf.createLiteral(data.get("id").toString()));

                // schema:name is the facebook name (can have multiple languages)
                con.add(subject, SCHEMA.name, vf.createLiteral(data.get("name").toString(), language));
                con.add(subject, DCTERMS.title, vf.createLiteral(data.get("name").toString(), language));

                // dct:description in case a description or about is present (all content in English)
                if(data.get("description") != null) {
                    con.add(subject,SCHEMA.description, vf.createLiteral(data.get("description").toString(), "en"));
                    con.add(subject,DCTERMS.description, vf.createLiteral(data.get("description").toString(), "en"));
                }
                if(data.get("about") != null) {
                    con.add(subject,SCHEMA.description, vf.createLiteral(data.get("about").toString(), "en"));
                    con.add(subject,DCTERMS.description, vf.createLiteral(data.get("about").toString(), "en"));
                }

                // if there is genre information, add it using schema:genre and dct:subject
                if(data.get("genre") != null) {
                    con.add(subject,SCHEMA.genre, vf.createLiteral(data.get("genre").toString()));
                    con.add(subject,DCTERMS.subject, vf.createLiteral(data.get("genre").toString()));
                }
                if(data.get("directed_by") != null) {
                    con.add(subject,SCHEMA.director, vf.createLiteral(data.get("directed_by").toString()));
                    con.add(subject,DCTERMS.creator, vf.createLiteral(data.get("directed_by").toString()));
                }
                if(data.get("studio") != null) {
                    con.add(subject,SCHEMA.publisher, vf.createLiteral(data.get("studio").toString()));
                    con.add(subject,DCTERMS.publisher, vf.createLiteral(data.get("studio").toString()));
                }
                if(data.get("plot_outline") != null) {
                    con.add(subject,SCHEMA.description, vf.createLiteral(data.get("plot_outline").toString()));
                    con.add(subject,DCTERMS.description, vf.createLiteral(data.get("plot_outline").toString()));
                }
                if(data.get("phone") != null) {
                    con.add(subject,SCHEMA.telephone, vf.createLiteral(data.get("phone").toString()));
                    con.add(subject,FOAF.phone, vf.createLiteral(data.get("phone").toString()));
                }
                if(data.get("username") != null) {
                    con.add(subject,FOAF.nick, vf.createLiteral(data.get("username").toString()));
                }

                if(data.get("cover") != null && data.get("cover") instanceof Map && ((Map)data.get("cover")).get("source") != null) {
                    con.add(subject,FOAF.thumbnail, vf.createURI(((Map) data.get("cover")).get("source").toString()));
                }



                // website
                if(data.get("website") != null && UriUtil.validate(data.get("website").toString())) {
                    con.add(subject, FOAF.homepage, vf.createURI(data.get("website").toString()));
                }
                if(data.get("link") != null) {
                    con.add(subject, FOAF.homepage, vf.createURI(data.get("link").toString()));
                }

                con.commit();
            } catch(RepositoryException ex) {
                con.rollback();
View Full Code Here

                namespaces.add(Namespace.getNamespace(ns.getKey(), ns.getValue()));
            }


            RepositoryConnection con = triples.getConnection();
            ValueFactory vf = con.getValueFactory();

            Resource subject = vf.createURI(resource);

            for(Map.Entry<String,XPathValueMapper> mapping : getXPathMappings(requestUrl).entrySet()) {
                XPathExpression<Object> xpath = mapping.getValue().getCompiled();

                org.openrdf.model.URI predicate = triples.getValueFactory().createURI(mapping.getKey());
                for(Object value : xpath.evaluate(doc)) {
                    String str_value;
                    if(value instanceof Element) {
                        str_value = ((Element) value).getValue();
                    } else if(value instanceof Text) {
                        str_value = ((Text) value).getValue();
                    } else if(value instanceof Attribute) {
                        str_value = ((Attribute) value).getValue();
                    } else if(value instanceof CDATA) {
                        str_value = ((CDATA) value).getValue();
                    } else if(value instanceof Comment) {
                        str_value = ((Comment) value).getValue();
                    } else {
                        str_value = value.toString();
                    }
                    List<Value> objects = mapping.getValue().map(resource, str_value,triples.getValueFactory());
                    for(Value object : objects) {
                        Statement stmt = triples.getValueFactory().createStatement(subject,predicate,object);
                        con.add(stmt);
                    }
                }
            }

            org.openrdf.model.URI ptype = triples.getValueFactory().createURI(Namespaces.NS_RDF + "type");
           
            for(String typeUri : getTypes(vf.createURI(resource))) {
                Resource type_resource = vf.createURI(typeUri);
                con.add(vf.createStatement(subject, ptype, type_resource));
            }

            con.commit();
            con.close();
View Full Code Here

            Repository rep = new SailRepository(new MemoryStore());
            rep.initialize();

            RepositoryConnection conn = rep.getConnection();
            try {
                ValueFactory vf = conn.getValueFactory();
                String userDN = buildDN(prefix, account, ldap);

                Map<String, java.util.List<String>> accountData = getAccountData(userDN, ldap);

                final URI subject = vf.createURI(resource);
                for (String attr : MAPPING.keySet()) {
                    if (!accountData.containsKey(attr)) {
                        continue;
                    }

                    final PredicateObjectFactory factory = MAPPING.get(attr);
                    final URI predicate = factory.createPredicate(vf);

                    for (String val : accountData.get(attr)) {
                        for (Value object : factory.createObjects(val, vf)) {
                            conn.add(vf.createStatement(subject, predicate, object));
                        }
                    }

                }
View Full Code Here

        subject = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));
        predicate = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));

        final SailRepositoryConnection con = repository.getConnection();
        try {
            final ValueFactory vf = con.getValueFactory();

            con.add(vf.createStatement(subject, predicate, vf.createLiteral(text)));

            con.commit();
        } finally {
            con.close();
        }
View Full Code Here

            final Context context = Context.fromUrl(requestUrl);
            final Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(in);

            ArrayList<String> followUp = new ArrayList<String>();
            final RepositoryConnection con = repository.getConnection();
            final ValueFactory valueFactory = con.getValueFactory();

            switch (context) {
                case SITE:
                    followUp.addAll(parseSiteMeta(resource, requestUrl, doc, repository));
                    break;
                case META:
                case META_CONTINUED:
                    // For Articles: Retrieve article info (sioc:WikiArticle)
                    // Follow-Up: resolve titles: links, categories
                    // For Categories: Retrieve as skos:Concept/sioc:Category
                    followUp.addAll(parseArticleMeta(resource, requestUrl, doc, context, repository));
                    break;
                case CONTENT:
                    followUp.addAll(parseRevision(valueFactory.createURI(resource), requestUrl, con, valueFactory, queryElement(doc, "/api/query/pages/page[1]/revisions"),
                            context));
                    break;
                /* Links from an Article */
                case REDIRECT:
                case LINKS:
View Full Code Here

TOP

Related Classes of org.openrdf.model.ValueFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.