Skip to content

Commit

Permalink
Add account description on node properties
Browse files Browse the repository at this point in the history
  • Loading branch information
totetmatt committed Oct 30, 2023
1 parent 7420b3a commit 49995c5
Showing 1 changed file with 57 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public class BlueskyGephi {
private final static String NBPREF_QUERY_ISDEEPSEARCH = "query.isDeepSearch";
private final static String NBPREF_QUERY_ISLIMITCRAWLACTIVE = "query.isLimitCrawlActive";
private final static String NBPREF_QUERY_LIMITCRAWL = "query.limitCrawl";

private final Preferences nbPref = NbPreferences.forModule(BlueskyGephi.class);
// If ATProto get released and decentralized, this will change to adapt to other instances
final private AtClient client = new AtClient("bsky.social");
private GraphModel graphModel;

public BlueskyGephi() {
initProjectAndWorkspace();

}

private void initProjectAndWorkspace() {
Expand Down Expand Up @@ -110,27 +110,30 @@ public void setIsDeepSearch(boolean setIsDeepSearch) {
public boolean getIsDeepSearch() {
return nbPref.getBoolean(NBPREF_QUERY_ISDEEPSEARCH, true);
}
public void setIsLimitCrawlActive(boolean isLimitCrawlActive){
nbPref.putBoolean(NBPREF_QUERY_ISLIMITCRAWLACTIVE, isLimitCrawlActive);

public void setIsLimitCrawlActive(boolean isLimitCrawlActive) {
nbPref.putBoolean(NBPREF_QUERY_ISLIMITCRAWLACTIVE, isLimitCrawlActive);
}
public boolean getIsLimitCrawlActive(){

public boolean getIsLimitCrawlActive() {
return nbPref.getBoolean(NBPREF_QUERY_ISLIMITCRAWLACTIVE, true);
}


public void setLimitCrawl(int limitCrawl){
nbPref.putInt(NBPREF_QUERY_LIMITCRAWL, limitCrawl);
public void setLimitCrawl(int limitCrawl) {
nbPref.putInt(NBPREF_QUERY_LIMITCRAWL, limitCrawl);
}
public int getLimitCrawl(){

public int getLimitCrawl() {
return nbPref.getInt(NBPREF_QUERY_LIMITCRAWL, 50);
}

private Node createNode(Identity i) {

Node node = graphModel.getGraph().getNode(i.getDid());
if (node == null) {
node = graphModel.factory().newNode(i.getDid());
node.setLabel(i.getHandle());
node.setAttribute("Description", i.getDescription());
node.setSize(10);
node.setColor(Color.GRAY);
node.setX((float) ((0.01 + Math.random()) * 1000) - 500);
Expand Down Expand Up @@ -161,12 +164,11 @@ private void fetchFollowerFollowsFromActor(String actor, List<String> listInit,
Set<String> foaf = new HashSet<>();

private void process(String actor, boolean isDeepSearch, Optional<Integer> limitCrawl) {

try {
if (isFollowsActive) {
List<AppBskyGraphGetFollows> responses = client.appBskyGraphGetFollows(actor,limitCrawl);
List<AppBskyGraphGetFollows> responses = client.appBskyGraphGetFollows(actor, limitCrawl);


for (var response : responses) {
graphModel.getGraph().writeLock();
Identity subject = response.getSubject();
Expand All @@ -182,14 +184,12 @@ private void process(String actor, boolean isDeepSearch, Optional<Integer> limit
graphModel.getGraph().writeUnlock();

}



}

if (isFollowersActive) {
List<AppBskyGraphGetFollowers> responses = client.appBskyGraphGetFollowers(actor,limitCrawl);
List<AppBskyGraphGetFollowers> responses = client.appBskyGraphGetFollowers(actor, limitCrawl);


for (var response : responses) {
graphModel.getGraph().writeLock();
Identity subject = response.getSubject();
Expand All @@ -204,21 +204,21 @@ private void process(String actor, boolean isDeepSearch, Optional<Integer> limit
}
graphModel.getGraph().writeUnlock();
}

}
} catch(Exception e){
Exceptions.printStackTrace(e);
} catch (Exception e) {
Exceptions.printStackTrace(e);
} finally {
}
}

@Override
public void run() {
if(actor!=null){
this.setName("[Bsky] fetching" + actor);

if (actor != null) {
this.setName("[Bsky] fetching" + actor);
} else {
this.setName("[Bsky] fetching List");
this.setName("[Bsky] fetching List");
}
progressTicket = Lookup.getDefault()
.lookup(ProgressTicketProvider.class)
Expand All @@ -229,25 +229,24 @@ public void run() {
});
Progress.start(progressTicket);
Progress.switchToIndeterminate(progressTicket);


if(listInit!=null){

if (listInit != null) {
this.foaf.addAll(listInit);
}
if(actor!=null){
process(actor, isDeepSearch,Optional.empty());
if (actor != null) {
process(actor, isDeepSearch, Optional.empty());
}
if (listInit!=null||isDeepSearch ) {
if (listInit != null || isDeepSearch) {
Progress.switchToDeterminate(progressTicket, foaf.size());
for (var foafActor : foaf) {
Progress.setDisplayName(progressTicket, "[Bsky] fetching "+actor+" n+1 > "+foafActor);
if(getIsLimitCrawlActive()){
process(foafActor, false,Optional.of(getLimitCrawl()));
Progress.setDisplayName(progressTicket, "[Bsky] fetching " + actor + " n+1 > " + foafActor);
if (getIsLimitCrawlActive()) {
process(foafActor, false, Optional.of(getLimitCrawl()));
} else {
process(foafActor, false,Optional.empty());
process(foafActor, false, Optional.empty());
}
Progress.progress(progressTicket);

}
}
Progress.finish(progressTicket);
Expand All @@ -256,31 +255,41 @@ public void run() {
t.start();

}

private Stream<String> manageList(String listId) {
List<AppBskyGraphGetList> list = client.appBskyGraphGetList(listId);
return list.stream().flatMap(x->x.getItems().stream().map(y->y.getSubject().getDid()));

List<AppBskyGraphGetList> list = client.appBskyGraphGetList(listId);
return list.stream().flatMap(x -> x.getItems().stream().map(y -> y.getSubject().getDid()));

}

private void initGraphTable() {
// Create necessary model for the graph entities
if (!graphModel.getNodeTable().hasColumn("Description")) {
graphModel.getNodeTable().addColumn("Description", String.class);
}
}

public void fetchFollowerFollowsFromActors(List<String> actors, boolean isFollowsActive, boolean isFollowersActive, boolean isBlocksActive) {
graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
actors.stream().forEach(actor -> fetchFollowerFollowsFromActor(actor,null, isFollowsActive, isFollowersActive, getIsDeepSearch()));
initGraphTable();
actors.stream().forEach(actor -> fetchFollowerFollowsFromActor(actor, null, isFollowsActive, isFollowersActive, getIsDeepSearch()));
}


public void fetchFollowerFollowsFromActors(List<String> actors) {
graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
actors
.stream()
.filter(x -> !x.contains("app.bsky.graph.list"))
.forEach(actor -> fetchFollowerFollowsFromActor(actor,null, getIsFollowsActive(), getIsFollowersActive(), getIsDeepSearch()));

initGraphTable();
actors
.stream()
.filter(x -> !x.contains("app.bsky.graph.list"))
.forEach(actor -> fetchFollowerFollowsFromActor(actor, null, getIsFollowsActive(), getIsFollowersActive(), getIsDeepSearch()));

List<String> listActor = actors
.stream()
.filter(x -> x.contains("app.bsky.graph.list"))
.flatMap(this::manageList)
.collect(Collectors.toList());
fetchFollowerFollowsFromActor(null,listActor, getIsFollowsActive(), getIsFollowersActive(), getIsDeepSearch());

fetchFollowerFollowsFromActor(null, listActor, getIsFollowsActive(), getIsFollowersActive(), getIsDeepSearch());

}
}

0 comments on commit 49995c5

Please sign in to comment.