com.hp.hpl.jena.util.iterator.ExtendedIterator Java Examples

The following examples show how to use com.hp.hpl.jena.util.iterator.ExtendedIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessingUtils.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
public static List<String> getAllClasses ()
{
   List<String>classes = new ArrayList<String>();
   DrbCortexModel model;
   try
   {
      model = DrbCortexModel.getDefaultModel();
   }
   catch (IOException e)
   {
      return classes;
   }
   ExtendedIterator it= model.getCortexModel().getOntModel().listClasses();
   while (it.hasNext())
   {
      OntClass cl = (OntClass)it.next();
      String uri = cl.getURI();
      if (uri!=null)
         classes.add(uri);
   }
   return classes;
}
 
Example #2
Source File: ConceptImpl.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setParentConcept(ObjectClass parent) {
	if (parent != null) {
		this.addProperty(RDFS.subClassOf, parent.asMDRResource());
	} else {
		ExtendedIterator<OntClass> l = this.listSuperClasses();
		OntClass found = null;
		while (l.hasNext()) {
			OntClass ontClass = l.next();
			if (ontClass.hasSuperClass(mdrDatabase.getVocabulary().Concept)) {
				found = ontClass;
			}
		}
		if (found != null) {
			this.removeProperty(RDFS.subClassOf, found);
		}
	}
}
 
Example #3
Source File: D2RQQueryHandler.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
public BindingQueryPlan prepareBindings(GraphQuery q, Node[] variables) {   
	this.variables = variables;
	this.indexes = new HashMap<Node,Integer>();
	for (int i = 0; i < variables.length; i++) {
		indexes.put(variables[i], new Integer(i));
	}
	BasicPattern pattern = new BasicPattern();
	for (Triple t: q.getPattern()) {
		pattern.add(t);
	}
	Plan plan = QueryEngineD2RQ.getFactory().create(new OpBGP(pattern), dataset, null, null);
	final ExtendedIterator<Domain> queryIterator = new Map1Iterator<Binding,Domain>(new BindingToDomain(), plan.iterator());
	return new BindingQueryPlan() {
		public ExtendedIterator<Domain> executeBindings() {
			return queryIterator;
		}
	};
}
 
Example #4
Source File: ProcessingUtils.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public static List<String>getSubClass(String URI)
{
   List<String>sub_classes = new ArrayList<String>();
   DrbCortexItemClass cl = DrbCortexItemClass.getCortexItemClassByName(URI);
   ExtendedIterator it = cl.getOntClass().listSubClasses(true);
   while (it.hasNext())
   {
      String ns = ((OntClass)it.next()).getURI();
      if(ns!=null) sub_classes.add(ns);
   }
   return sub_classes;
}
 
Example #5
Source File: ConceptImpl.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ObjectClass> getSubConcepts() {
	ExtendedIterator<OntClass> l = this.listSubClasses();
	List<ObjectClass> ocList = new ArrayList<ObjectClass>();

	while (l.hasNext()) {
		OntClass res = l.next();
		ocList.add(new ConceptImpl(res, mdrDatabase));
	}

	return ocList;
}
 
Example #6
Source File: Util.java    From semanticMDR with GNU General Public License v3.0 5 votes vote down vote up
public <T extends MDRResource> List<T> createList(ExtendedIterator<? extends RDFNode> it,
		Class<T> cls) throws MDRException {

	List<T> newList = new ArrayList<T>();
	try {
		Transformer transformer = transformerMap.get(cls);
		CollectionUtils.collect(it, transformer, newList);
	} catch (Exception e) {
		throw new MDRException(e);
	}
	return newList;
}
 
Example #7
Source File: SolRDFGraph.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
public ExtendedIterator<Triple> graphBaseFind(final Triple pattern) {	
	try {
		return WrappedIterator.createNoRemove(query(pattern));
	} catch (final SyntaxError exception) {
		logger().error(MessageCatalog._00113_NWS_FAILURE, exception);
		return new NullIterator<Triple>();
	}
}
 
Example #8
Source File: GraphD2RQ.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
@Override
public ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
	checkOpen();
	Triple t = m.asTriple();
	if (log.isDebugEnabled()) {
		log.debug("Find: " + PrettyPrinter.toString(t, getPrefixMapping()));
	}
	FindQuery query = new FindQuery(t, mapping.getTripleRelations(), 
			new ExecutionContext(mapping.getContext(), this, null, null));
	ExtendedIterator<Triple> result = TripleQueryIter.create(query.iterator());
	result = result.andThen(mapping.getAdditionalTriples().find(t));
	return result;
   }
 
Example #9
Source File: CachingGraphD2RQ.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
/**
 * Overloaded to reuse and update the cache.
 */
@Override
public ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
	List<Triple> cached = queryCache.get(m);
	if (cached != null) {
           return WrappedIterator.create(cached.iterator());
	}
	ExtendedIterator<Triple> it = super.graphBaseFind(m);
	final List<Triple> list = it.toList();
	queryCache.put(m, list);
	return WrappedIterator.create(list.iterator());
}
 
Example #10
Source File: ProcessingUtils.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public static List<String>getSuperClass(String URI)
{
   List<String>super_classes = new ArrayList<String>();
   DrbCortexItemClass cl = DrbCortexItemClass.getCortexItemClassByName(URI);
   ExtendedIterator it = cl.getOntClass().listSuperClasses(true);
   while (it.hasNext())
   {
      String ns = ((OntClass)it.next()).getURI();
      if(ns!=null) super_classes.add(ns);
   }
   return super_classes;
}
 
Example #11
Source File: ScannerFactory.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Retrieve the dhus system supported items for file scanning processing.
 * Is considered supported all classes having
 * <code>http://www.gael.fr/dhus#metadataExtractor</code> property
 * connection.
 * @return the list of supported class names.
 */
public static synchronized String[] getDefaultCortexSupport ()
{
   DrbCortexModel model;
   try
   {
      model = DrbCortexModel.getDefaultModel ();
   }
   catch (IOException e)
   {
      throw new UnsupportedOperationException (
         "Drb cortex not properly initialized.");
   }

   ExtendedIterator it=model.getCortexModel ().getOntModel ().listClasses ();
   List<String>list = new ArrayList<String> ();

   while (it.hasNext ())
   {
      OntClass cl = (OntClass)it.next ();

      OntProperty metadata_extractor_p = cl.getOntModel().getOntProperty(
            "http://www.gael.fr/dhus#support");

      StmtIterator properties = cl.listProperties (metadata_extractor_p);
      while (properties.hasNext ())
      {
         Statement stmt = properties.nextStatement ();
         LOGGER.debug ("Scanner Support Added for " +
            stmt.getSubject ().toString ());
         list.add (stmt.getSubject ().toString ());
      }
   }
   return list.toArray (new String[list.size ()]);
}
 
Example #12
Source File: GeneralGraphD2RQ.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
@Override
public ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
	checkOpen();
	Triple t = m.asTriple();
	if (log.isDebugEnabled()) {
		log.debug("Find: " + PrettyPrinter.toString(t, getPrefixMapping()));
	}
	ExecutionContext context = new ExecutionContext(mapping.getContext(), this, null, null);
	GeneralFindQuery query = new GeneralFindQuery(t, mapping.getTripleRelations(), context);
	ExtendedIterator<Triple> result = TripleQueryIter.create(query.iterator());
	result = result.andThen(mapping.getAdditionalTriples().find(t));
	return result;
   }
 
Example #13
Source File: NeoGraph.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
/**
 * Find the given triple(s) from the graph. 
 */
@Override
public ExtendedIterator<Triple> find(TripleMatch triple) {
	return find(triple.getMatchSubject(),triple.getMatchPredicate(), triple.getMatchObject());
}
 
Example #14
Source File: OntologyLoader.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public ExtendedIterator<OntClass> getClasses() {
	return model.listClasses();
}
 
Example #15
Source File: Neo4j.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
@Override
public ExtendedIterator<Triple> find(Node arg0, Node arg1, Node arg2) {
	// TODO Auto-generated method stub
	return null;
}
 
Example #16
Source File: Neo4j.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
@Override
public ExtendedIterator<Triple> find(TripleMatch arg0) {
	// TODO Auto-generated method stub
	return null;
}
 
Example #17
Source File: NeoGraphMaker.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
@Override
public ExtendedIterator listGraphs() {
	// TODO Auto-generated method stub
	return null;
}
 
Example #18
Source File: NeoGraph.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
/**
 * Find the given triple(s) from the graph. 
 */
@Override
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
	//System.out.println("NeoGraph#find");
	try(Transaction tx = graphdb.beginTx()) {
		StringBuffer query = new StringBuffer("MATCH triple=");
		
		query.append("(subject");
		if(subject.equals(Node.ANY)) {
			query.append(":"+ LABEL_URI);
			//System.out.println("NeoGraph#find#Any:"+subject);
		} else if(subject.isURI()){
			query.append(":"+LABEL_URI+" {uri:'");
			query.append(subject.getURI());
			query.append("'}");
			//System.out.println("NeoGraph#find#URI:"+subject+subject.getURI());
		} else {
			query.append(":" + LABEL_BNODE);
			//System.out.println("NeoGraph#find#"+subject);
		}
		query.append(")-[predicate]->(object");
		
		//query.append("]->(object");
		if(object.equals(Node.ANY)) {
			//query.append(" ");
		} else if(object.isURI()){
			query.append(":"+LABEL_URI+" {uri:'");
			query.append(object.getURI());
			query.append("'}");
		} else {
			query.append(":"+LABEL_LITERAL+" {value:'");
			query.append(object.getLiteralValue());
			query.append("'}");
		}
		query.append(")");
		
		//System.out.println("Predicate in query: " +getPrefixMapping().shortForm(predicate.getURI()));
		if(predicate.isURI()) {
			query.append("WHERE type(predicate)='");
			query.append(getPrefixMapping().shortForm(predicate.getURI()));
			query.append("'");
		}
		
		query.append("\nRETURN subject, type(predicate), object");
		//System.out.println(query.toString());
		ExecutionEngine engine = new ExecutionEngine(graphdb);
		ExecutionResult results = engine.execute(query.toString());
		//System.out.println(results.dumpToString());
		//System.out.println("NeoGraph#find#"+predicate);
		//System.out.println("NeoGraph#find#"+object);
		//System.out.println("NeoGraph#find#DONE");
		return new ExecutionResultIterator(results, graphdb);
	}
}
 
Example #19
Source File: ExecutionResultIterator.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
@Override
public <U> ExtendedIterator<U> mapWith(Map1<Triple, U> map1) {
	// TODO Auto-generated method stub
	return null;
}
 
Example #20
Source File: ExecutionResultIterator.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
@Override
public ExtendedIterator<Triple> filterDrop(Filter<Triple> f) {
	// TODO Auto-generated method stub
	return null;
}
 
Example #21
Source File: ExecutionResultIterator.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
@Override
public ExtendedIterator<Triple> filterKeep(Filter<Triple> f) {
	// TODO Auto-generated method stub
	return null;
}
 
Example #22
Source File: ExecutionResultIterator.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
@Override
public <X extends Triple> ExtendedIterator<Triple> andThen(Iterator<X> other) {
	// TODO Auto-generated method stub
	return null;
}
 
Example #23
Source File: GeoTriplesWindow.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public void loadOntologyFromFile() {
   	final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
	fileBrowserSheet.setName("Select an ontology file");
	fileBrowserSheet.setDisabledFileFilter(new Filter<File>() {                     
       @Override 
       public boolean include(File file) { 
           return (file.isFile() 
               && !file.getName().endsWith(".rdf")); 
       } 
   }); 
	fileBrowserSheet.setMode(org.apache.pivot.wtk.FileBrowserSheet.Mode.OPEN);
	fileBrowserSheet.open(GeoTriplesWindow.this, new SheetCloseListener() {
		@Override
		public void sheetClosed(Sheet sheet) {
			if (sheet.getResult()) {
				Sequence<File> selectedFiles = fileBrowserSheet
						.getSelectedFiles();

				ListView listView = new ListView();
				listView.setListData(new ArrayList<File>(selectedFiles));
				listView.setSelectMode(ListView.SelectMode.NONE);
				listView.getStyles().put("backgroundColor", null);
				
				try {
					ontologyPath = selectedFiles.get(0).getCanonicalPath();
					if(ontologyPath==null)
					{
						Alert.alert(MessageType.ERROR, "Something went wrong with the file,  please try again",GeoTriplesWindow.this);
						return;
					}
					
					OntologyLoader loader = new OntologyLoader(ontologyPath);
					loader.load();
					
					/**
		             * for properties
		             */
					List<String> preds = new ArrayList<String>();
	            	ExtendedIterator<DatatypeProperty> props = loader.getProperties();
	            	while (props.hasNext()) {
	            		preds.add(props.next().getLocalName());
	            	}
	            	
		            /**
		             * for classes
		             */
		            List<String> classes = new ArrayList<String>();
	            	ExtendedIterator<OntClass> classS = loader.getClasses();
	            	while (classS.hasNext()) {
	            		classes.add(classS.next().getLocalName());
	            	}

	            	for(SourceTable st:sourceTables)
		            {
		            	st.setClasses(classes);
		            	st.setPredicates(preds);
		            }
				} catch (IOException e) {
					System.out.println(e.getMessage());
					e.printStackTrace();
					System.exit(13);
				}
			} 	
			}
	});			
	/*
	 * ApplicationContext.scheduleRecurringCallback(new Runnable() {
	 * 
	 * @Override public void run() { refreshTable(); } }, REFRESH_INTERVAL);
	 */
}
 
Example #24
Source File: OntologyLoader.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public ExtendedIterator<DatatypeProperty> getProperties() {
	return model.listDatatypeProperties();
}
 
Example #25
Source File: GeneralTripleQueryIter.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public static ExtendedIterator<Triple> create(QueryIter wrapped) {
	return new GeneralTripleQueryIter(wrapped);
}
 
Example #26
Source File: TripleQueryIter.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public static ExtendedIterator<Triple> create(QueryIter wrapped) {
	return new TripleQueryIter(wrapped);
}
 
Example #27
Source File: R2RMLReader.java    From GeoTriples with Apache License 2.0 2 votes vote down vote up
private TermMap createTransformationValuedTermMap(Resource r) {
	TransformationValuedTermMap result = new TransformationValuedTermMap();
	result.setFunction(ConstantIRI.create(getString(r, RRX.function)));
	
	
	List<TermMap> arguments=new ArrayList<TermMap>();
	//Resource list = getResource(r, RRX.argumentMap);
	
	RDFNode list2 = r.getProperty(RRX.argumentMap).getObject();;
	
	
	
	RDFList rdfList = list2.as( RDFList.class );
       ExtendedIterator<RDFNode> items = rdfList.iterator();
       while ( items.hasNext() ) {
           Resource item = items.next().asResource();            
           if(item.getProperty(RR.constant)!=null)
           {
   			arguments.add(createConstantValuedTermMap(item));
   		}
           if(item.getProperty(RR.column)!=null) {
			arguments.add(createColumnValuedTermMap(item));
		}
		if(item.getProperty(RRX.function)!=null) {
			arguments.add(createTransformationValuedTermMap(item));
		}
		if(item.getProperty(RR.template)!=null) {
			arguments.add(createTemplateValuedTermMap(item));
		}
           
       }
	
	
	
	
	
	
	
	
       
	result.setTermMaps(arguments);
	readColumnOrTemplateValuedTermMap(result, r);
	return result;
}