I am using GraphStream in a project and my problem is that I want to retrieve the list of connected components but I only get either their count or at the very best their Ids.
I have tried this code but it doesn't return anything :
ConnectedComponents cc = new ConnectedComponents();
cc.init(graph);
System.out.println("List of Connected Components :");
for(ConnectedComponent conn : cc) {
System.out.println("Component " + conn.id + " :");
System.out.println("--------------");
for(Node n : conn.getEachNode()) {
Object[] attr = n.getAttribute("xy");
Double x = (Double) attr[0];
Double y = (Double) attr[1];
System.out.println(x + " , " + y);
}
}
The nodes have an attribute "xy" which contains the coordinates stored as Double[].
What did I do wrong? And how can I fix it?
ConnectedComponents has been rewritten in commit on 2015-12-15. There was a problem with retrieving content of components.
If you are not using the git version of GraphStream, maybe you should give it a try.
Related
I'm using Oracle Big Data Spatial & Graph v.2.5 and following the official guide to load through Java a Graph on HBase.
This is my code:
public class Main {
public static void main(String[] arg) throws Exception {
org.apache.log4j.BasicConfigurator.configure();
OraclePropertyGraphDataLoader opgdl = OraclePropertyGraphDataLoader.getInstance();
String vfile = "/root/oracle_property_files/connections.opv";
String efile = "/root/oracle_property_files/connections.ope";
PgHbaseGraphConfig cfg = GraphConfigBuilder.forPropertyGraphHbase()
.setName("config").setZkQuorum("zk01node,zk02node,zk03node").build();
OraclePropertyGraph opg = OraclePropertyGraph.getInstance(cfg);
opgdl.loadData(opg, vfile, efile, 48);
}
}
Using this libraries:
This is my .opv file:
1,name,1,Alice,,
1,age,2,,31,
2,name,1,Bob,,
2,age,2,,27,
And this is my .ope file:
1,1,2,knows,type,1,friends,,
My code creates on HBase the tables: configEI.
configGE.
configIT.
configVI.
configVT.
The problem is that if I launch the command scan 'configVT.' The output is mixed in hexadecimal and ASCII values:
hbase(main):003:0> scan 'configVT.'
ROW COLUMN+CELL
3v\x93ur|\xD7\xD3\x00\x00\x00\x00\x00\x00\x00\x02 column=v:i\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01, timestamp=1624009988902, value=knows
3v\x93ur|\xD7\xD3\x00\x00\x00\x00\x00\x00\x00\x02 column=v:kage, timestamp=1624009989001, value=\x00\x00\x00\x1B\x02
3v\x93ur|\xD7\xD3\x00\x00\x00\x00\x00\x00\x00\x02 column=v:kname, timestamp=1624009989001, value=Bob\x01
\xCB\xFC%\xA7qt\x02\x84\x00\x00\x00\x00\x00\x00\x00 column=v:kage, timestamp=1624009988909, value=\x00\x00\x00\x1F\x02
\x01
\xCB\xFC%\xA7qt\x02\x84\x00\x00\x00\x00\x00\x00\x00 column=v:kname, timestamp=1624009988909, value=Alice\x01
\x01
\xCB\xFC%\xA7qt\x02\x84\x00\x00\x00\x00\x00\x00\x00 column=v:o\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x01, timestamp=1624009988909, value=knows
\x01
2 row(s) in 0.0490 seconds
I would like to have a more readable result.
Edit: It seems that String and Date types are stored correctly (but with some HEX escape character as Alice\x01). Instead the integers are totally converted to theirs HEX values.
I figured it out. Using the scan command, i read the tables as simply hbase tables, but they aren't, they are Oracle Big Data Spatial & Graph tables stored in hbase. So my configVT. table is only one of the five tables created with the java method opgdl.loadData and reading just it is not enough.
In order to get readable result, I should read it has edges or vertex:
opg.getVertices().forEach( e -> {
System.out.println("id vertex: " + e.getId());
e.getPropertyKeys().forEach(p -> {
System.out.println("property: " + p);
System.out.println("value: " + e.getProperty(p));
});
});
opg.getEdges().forEach( e -> {
System.out.println("label: " + e.getLabel());
System.out.println("id edge: " + e.getId());
Vertex vIn = e.getVertex(Direction.IN);
Vertex vOut = e.getVertex(Direction.OUT);
System.out.println("edge from: " + vOut.getId());
System.out.println("edge to: " + vIn.getId());
e.getPropertyKeys().forEach(p -> {
System.out.println("property: " + p);
System.out.println("value: " + e.getProperty(p));
});
});
As given in the docs of Apache Edgent I tried to filter out my sensor readings wherein the values of the temperature sensor must lie in between 80 to 85 F.
But when I tried connecting my sensor the readings were 75F and no message was shown like: temperature is out of range.
Is it that the filter method isn't working? if so please try help me out. thanks.
the range values are set as:
static double OPTIMAL_TEMP_LOW = 80.0;
static double OPTIMAL_TEMP_HIGH = 85.0;
static Range<Double> optimalTempRange = Ranges.closed(OPTIMAL_TEMP_LOW, OPTIMAL_TEMP_HIGH);
The sensor object is TempSensor ts
TempSensor ts = new TempSensor();
Stream<Double> temp = top.poll(ts, 1, TimeUnit.MILLISECONDS);
the filtering part:
TStream<Double> simpleFiltered = temp.filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
simpleFiltered.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));
/*TStream<Double> simpleFiltered = temp.filter(tuple ->
!optimalTempRange.contains(tuple));
simpleFiltered.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));*/
// See what the temperatures look like
simpleFiltered.print();
dp.submit(top);
output:
Selet a port:
1: ttyACM0 Port opened succesefully.
7373.40
73.40
73.40 ...
I think that happened because your filter and sink have been assigned to another TStream object, not the one you are printing out.
Probably you need to try this:
TempSensor ts = new TempSensor();
TStream<Double> temp = top.poll(ts, 1, TimeUnit.MILLISECONDS).filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
temp.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));
// See what the temperatures look like
temp.print();
dp.submit(top);
Hmm, your code matches the example in the documentation, but it looks as if we’re creating a filtered stream, and then ignoring it in temp.print().
You could try changing that line to simpleFiltered.print()
This is my first SQLite database with a float. I can't figure out why I am unable to store/retrieve the decimal parts of a float.
The database is defined as:
#Override
public void onCreate(SQLiteDatabase db){
// Create a string that contains the SQL statement to create the Nbmc device table
String SQL_CREATE_NBMC_TEMP_DATA_TABLE = "CREATE TABLE " + NbmcContract.NmbcTempData.TABLE_NAME + " ("
+ NbmcContract.NmbcTempData._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ NbmcContract.NmbcTempData.COLUMN_TIMESTAMP + " TEXT NOT NULL, "
+ NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT + " REAL) ";
db.execSQL(SQL_CREATE_NBMC_TEMP_DATA_TABLE);
}
I store floating point data in it from a service activity:
private static double lastSensorTempReading;
// ============ TEMP ==================
else if (UUID_SENSOR_FFF2.equals(characteristic.getUuid())) {
rxSensorDataType = FFF2_TEMP_CONST;
descStringBuilder.append("Elapsed Time: " + timeFormat.format(timeDiff) + "\n");
// temp comes in two bytes: newData[MSB], newData[LSB]
// temp = MSB + (0.1 * LSB)
int iTempMsb_i = (int) newData[0] & 0xff ;
int iTempLsb_i = (int) newData[1] & 0xff;
lastSensorTempReading = (float)iTempMsb_i + (0.10 * (float)iTempLsb_i);
Log.v("broadcastUpdate","Temp = " + lastSensorTempReading);
// Add this data to the temp Db
tempValues.put(NbmcContract.NmbcTempData.COLUMN_TIMESTAMP, estimatedTime);
tempValues.put(NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT, lastSensorTempReading);
newRowId = db_temp.insert(NbmcContract.NmbcTempData.TABLE_NAME, null, tempValues);
}
And, when I use the Log.v to dump the value I think I am storing it looks correct (and it looks correct when I send it to the Main Activity via an intent).
V/broadcastUpdate: Temp = 33.3
However, when I read it back from the SQLite database in my MainActivity, I'm losing the part of the float/double that follows the decimal point but I'm not getting errors reported in the Logcat.
sb.append(" ------------------- Temperature Data -------------------------\n");
nbmcTempDbHelper = new NbmcTempDataDbHelper( this.getApplicationContext());
SQLiteDatabase tmpDb = nbmcTempDbHelper.getReadableDatabase();
c = tmpDb.rawQuery(" SELECT " + NbmcContract.NmbcTempData._ID + ", "
+ NbmcContract.NmbcTempData.COLUMN_TIMESTAMP + ", "
+ NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT +
" FROM " + NbmcContract.NmbcTempData.TABLE_NAME +
" LIMIT " + MAX_RESULTS_RETRIEVED + " OFFSET " + 0, null);
try {
if (c != null) {
if (c.moveToFirst()) {
do {
String tempRowId = c.getString(c.getColumnIndexOrThrow(NbmcContract.NmbcTempData._ID));
String tempTimeString = c.getString(c.getColumnIndexOrThrow(NbmcContract.NmbcTempData.COLUMN_TIMESTAMP));
double tempDataDbl = c.getInt(c.getColumnIndexOrThrow(NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT));
Log.v("getEmailText", "Temp reading = " + tempDataDbl);
sb.append(tempRowId);
sb.append(DELIMITER);
sb.append(tempTimeString);
sb.append(DELIMITER);
sb.append(tempDataDbl);
sb.append(NEW_LINE);
} while (c.moveToNext());
}
}
} finally {
c.close();
tmpDb.close();
}
V/getEmailText: Temp reading = 30.0
V/getEmailText: Temp reading = 30.0
V/getEmailText: Temp reading = 30.0
V/getEmailText: Temp reading = 30.0
The problem is in this line
double tempDataDbl = c.getInt(c.getColumnIndexOrThrow(NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT));
While you are saving a Double you are retrieving an Integer. Just change the line to
double tempDataDbl = c.getDouble(c.getColumnIndexOrThrow(NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT));
Unfortunately AFAIK there is no way to get type mismatch. If you read through Data Types in SQLite it says :
In SQLite, the datatype of a value is associated with the value itself, not with its container. The dynamic type system of SQLite is backwards compatible with the more common static type systems of other database engines in the sense that SQL statements that work on statically typed databases should work the same way in SQLite. However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases.
Since any container e.g. INTEGER or REAL in your case can hold any and all kinds of data types and not even the database knows which type it is reading.
yes, dear
issue is at fetch time You having some problem with your code.
double tempDataDbl = c.getInt(c.getColumnIndexOrThrow(NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT));
change it to
double tempDataDbl = c.getDouble(c.getColumnIndexOrThrow(NbmcContract.NmbcTempData.COLUMN_DATA_FLOAT));
Below is a snippet of my code:
HierarchicalLDA hlda = new HierarchicalLDA();
hlda.initialize(instances, instances, 5, new Randoms());
hlda.estimate(1000);
hlda.printState(new PrintWriter(new File("Data.txt")));
I am unable to understand the meaning of both the console output and what is printed in the "Data.txt" file. I have already scoured the MALLET site but haven't found anything helpful. Any help or suggestion would be greatly appreciated.
Thanks in advance!
In hLDA each document samples a path through a tree of topics. Each token exists on one "level" of that path. The printState method gives you the ids of each tree node in the path for the document, followed by information about the word: the numeric ID for the word, the string for that id, and the level in the path.
node = documentLeaves[doc];
for (level = numLevels - 1; level >= 0; level--) {
path.append(node.nodeID + " ");
node = node.parent;
}
for (token = 0; token < seqLen; token++) {
type = fs.getIndexAtPosition(token);
level = docLevels[token];
// The "" just tells java we're not trying to add a string and an int
out.println(path + "" + type + " " + alphabet.lookupObject(type) + " " + level + " ");
}
I'm extracting named-entities from news articles with the use of Stanford NER CRFClassifier and in order to implement active learning, I would like to know what are the confidence scores of the classes for each labelled entity.
Exemple of display :
LOCATION(0.20) PERSON(0.10) ORGANIZATION(0.60) MISC(0.10)
Here is my code for extracting named-entities from a text :
AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier.getClassifierNoExceptions(classifier_path);
String annnotatedText = classifier.classifyWithInlineXML(text);
Is there a workaround to get thoses values along with the annotations ?
I've found it out by myself, in CRFClassifier's doc it is written :
Probabilities assigned by the CRF can be interrogated using either the
printProbsDocument() or getCliqueTrees() methods.
The first method is not useful since it only prints what I want on the console, but I want to be able to access this data, so I have read how this method is coded and copied a bit its behaviour like this :
List<CoreLabel> classifiedLabels = classifier.classify(sentences);
CRFCliqueTree<String> cliqueTree = classifier.getCliqueTree(classifiedLabels);
for (int i = 0; i < cliqueTree.length(); i++) {
CoreLabel wi = classifiedLabels.get(i);
for (Iterator<String> iter = classifier.classIndex.iterator(); iter.hasNext();) {
String label = iter.next();
int index = classifier.classIndex.indexOf(label);
double prob = cliqueTree.prob(i, index);
System.out.println("\t" + label + "(" + prob + ")");
}
String tag = StringUtils.getNotNullString(wi.get(CoreAnnotations.AnswerAnnotation.class));
System.out.println("Class : " + tag);
}