当前位置: 首页>>代码示例>>Java>>正文


Java Labels类代码示例

本文整理汇总了Java中com.maxdemarzi.Labels的典型用法代码示例。如果您正苦于以下问题:Java Labels类的具体用法?Java Labels怎么用?Java Labels使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Labels类属于com.maxdemarzi包,在下文中一共展示了Labels类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTrends

import com.maxdemarzi.Labels; //导入依赖的package包/类
private static List<Map<String, Object>> getTrends(String key) {
    ArrayList<Map<String, Object>> results = new ArrayList<>();
    LocalDateTime dateTime = LocalDateTime.now(utc);
    RelationshipType tagged = RelationshipType.withName("TAGGED_ON_" +
            dateTime.format(dateFormatter));
    try (Transaction tx = db.beginTx()) {
        ResourceIterator<Node> tags = db.findNodes(Labels.Tag);
        while (tags.hasNext()) {
            Node tag = tags.next();
            int taggings = tag.getDegree(tagged, Direction.INCOMING);
            if ( taggings > 0) {
                HashMap<String, Object> result = new HashMap<>();
                result.put(NAME, tag.getProperty(NAME));
                result.put(COUNT, taggings);
                results.add(result);
            }
        }
        tx.success();
    }

    results.sort(Comparator.comparing(m -> (Integer) m.get(COUNT), reverseOrder()));
    return results.subList(0, Math.min(results.size(), 10));
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:24,代码来源:Tags.java

示例2: createTags

import com.maxdemarzi.Labels; //导入依赖的package包/类
public static void createTags(Node post, HashMap<String, Object>  input, LocalDateTime dateTime, GraphDatabaseService db) {
    Matcher mat = hashtagPattern.matcher(((String)input.get("status")).toLowerCase());
    for (Relationship r1 : post.getRelationships(Direction.OUTGOING, RelationshipType.withName("TAGGED_ON_" +
            dateTime.format(dateFormatter)))) {
        r1.delete();
    }
    Set<Node> tagged = new HashSet<>();
    while (mat.find()) {
        String tag = mat.group(1);
        Node hashtag = db.findNode(Labels.Tag, NAME, tag);
        if (hashtag == null) {
            hashtag = db.createNode(Labels.Tag);
            hashtag.setProperty(NAME, tag);
            hashtag.setProperty(TIME, dateTime.truncatedTo(ChronoUnit.DAYS).toEpochSecond(ZoneOffset.UTC));
        }
        if (!tagged.contains(hashtag)) {
            post.createRelationshipTo(hashtag, RelationshipType.withName("TAGGED_ON_" +
                    dateTime.format(dateFormatter)));
            tagged.add(hashtag);
        }
    }
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:23,代码来源:Tags.java

示例3: Search

import com.maxdemarzi.Labels; //导入依赖的package包/类
public Search(@Context GraphDatabaseService db) throws NoSuchMethodException {
    this.dbapi = (GraphDatabaseAPI) db;
    try (Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        ReadOperations ops = ctx.get().readOperations();
        postLabelId = ops.labelGetForName(Labels.Post.name());
        statusPropertyId = ops.propertyKeyGetForName(STATUS);
        tx.success();
    }
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:11,代码来源:Search.java

示例4: createPost

import com.maxdemarzi.Labels; //导入依赖的package包/类
private Node createPost(@Context GraphDatabaseService db, HashMap input, Node user, LocalDateTime dateTime) {
    Node post = db.createNode(Labels.Post);
    post.setProperty(STATUS, input.get("status"));
    post.setProperty(TIME, dateTime.toEpochSecond(ZoneOffset.UTC));
    Relationship r1 = user.createRelationshipTo(post, RelationshipType.withName("POSTED_ON_" +
                    dateTime.format(dateFormatter)));
    r1.setProperty(TIME, dateTime.toEpochSecond(ZoneOffset.UTC));
    Tags.createTags(post, input, dateTime, db);
    Mentions.createMentions(post, input, dateTime, db);
    return post;
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:12,代码来源:Posts.java

示例5: createUser

import com.maxdemarzi.Labels; //导入依赖的package包/类
@POST
public Response createUser(String body, @Context GraphDatabaseService db) throws IOException {
    HashMap parameters = UserValidator.validate(body);
    Map<String, Object> results;
    try (Transaction tx = db.beginTx()) {
        Node user = db.findNode(Labels.User, USERNAME, parameters.get(USERNAME));
        if (user == null) {
            user = db.findNode(Labels.User, EMAIL, parameters.get(EMAIL));
            if (user == null) {
                user = db.createNode(Labels.User);
                user.setProperty(EMAIL, parameters.get(EMAIL));
                user.setProperty(NAME, parameters.get(NAME));
                user.setProperty(USERNAME, parameters.get(USERNAME));
                user.setProperty(PASSWORD, parameters.get(PASSWORD));
                user.setProperty(HASH, new Md5Hash(((String)parameters.get(EMAIL)).toLowerCase()).toString());

                LocalDateTime dateTime = LocalDateTime.now(utc);
                user.setProperty(TIME, dateTime.truncatedTo(ChronoUnit.DAYS).toEpochSecond(ZoneOffset.UTC));

                results = user.getAllProperties();
            } else {
                throw UserExceptions.existingEmailParameter;
            }
        } else {
            throw UserExceptions.existingUsernameParameter;
        }
        tx.success();
    }
    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:31,代码来源:Users.java

示例6: generate

import com.maxdemarzi.Labels; //导入依赖的package包/类
@Procedure(name = "com.maxdemarzi.schema.generate", mode = Mode.SCHEMA)
@Description("CALL com.maxdemarzi.schema.generate() - generate schema")

public Stream<StringResult> generate() throws IOException {
    org.neo4j.graphdb.schema.Schema schema = db.schema();
    if (!schema.getIndexes(Labels.Attribute).iterator().hasNext()) {
        schema.constraintFor(Labels.Attribute)
                .assertPropertyIsUnique("name")
                .create();
    }
    if (!schema.getIndexes(Labels.Path).iterator().hasNext()) {
        schema.constraintFor(Labels.Path)
                .assertPropertyIsUnique("id")
                .create();
    }
    if (!schema.getIndexes(Labels.Rule).iterator().hasNext()) {
        schema.constraintFor(Labels.Rule)
                .assertPropertyIsUnique("id")
                .create();
    }
    if (!schema.getIndexes(Labels.User).iterator().hasNext()) {
        schema.constraintFor(Labels.User)
                .assertPropertyIsUnique("username")
                .create();
    }
    return Stream.of(new StringResult("Schema Generated"));
}
 
开发者ID:maxdemarzi,项目名称:rule_matcher,代码行数:28,代码来源:Schema.java

示例7: getMetro

import com.maxdemarzi.Labels; //导入依赖的package包/类
private Node getMetro(@Context GraphDatabaseService db, HashMap<String, Node> metros, CSVRecord record) {
    Node metro = metros.get(record.get("metro_code"));
    if (metro == null) {
        metro = db.createNode(Labels.Metro);
        metro.setProperty("code", record.get("metro_code"));
    }
    return metro;
}
 
开发者ID:maxdemarzi,项目名称:import_maxmind,代码行数:9,代码来源:Locations.java

示例8: getTimezone

import com.maxdemarzi.Labels; //导入依赖的package包/类
private Node getTimezone(@Context GraphDatabaseService db, HashMap<String, Node> timezones, CSVRecord record) {
    Node timezone = timezones.get(record.get("time_zone"));
    if (timezone == null) {
        timezone = db.createNode(Labels.Timezone);
        timezone.setProperty("name", record.get("time_zone"));
        timezones.put(record.get("time_zone"), timezone);
    }
    return timezone;
}
 
开发者ID:maxdemarzi,项目名称:import_maxmind,代码行数:10,代码来源:Locations.java

示例9: getState

import com.maxdemarzi.Labels; //导入依赖的package包/类
private Node getState(@Context GraphDatabaseService db, HashMap<String, Node> states, CSVRecord record) {
    Node state = states.get(record.get("subdivision_1_iso_code"));
    if (state == null) {
        state = db.createNode(Labels.State);
        state.setProperty("code", record.get("subdivision_1_iso_code"));
        state.setProperty("name", record.get("subdivision_1_name"));
        states.put(record.get("subdivision_1_iso_code"), state);
    }
    return state;
}
 
开发者ID:maxdemarzi,项目名称:import_maxmind,代码行数:11,代码来源:Locations.java

示例10: getCountry

import com.maxdemarzi.Labels; //导入依赖的package包/类
private Node getCountry(GraphDatabaseService db, HashMap<String, Node> countries, CSVRecord record) {
    Node country = countries.get(record.get("country_iso_code"));
    if (country == null) {
        country = db.createNode(Labels.Country);
        country.setProperty("code", record.get("country_iso_code"));
        country.setProperty("name", record.get("country_name"));
        countries.put(record.get("country_iso_code"), country);
    }
    return country;
}
 
开发者ID:maxdemarzi,项目名称:import_maxmind,代码行数:11,代码来源:Locations.java

示例11: getContinent

import com.maxdemarzi.Labels; //导入依赖的package包/类
private Node getContinent(GraphDatabaseService db, HashMap<String, Node> continents, CSVRecord record) {
    Node continent = continents.get(record.get("continent_code"));
    if (continent == null) {
        continent = db.createNode(Labels.Continent);
        continent.setProperty("code", record.get("continent_code"));
        continent.setProperty("name", record.get("continent_name"));
        continents.put(record.get("continent_code"), continent);
    }
    return continent;
}
 
开发者ID:maxdemarzi,项目名称:import_maxmind,代码行数:11,代码来源:Locations.java

示例12: getLatest

import com.maxdemarzi.Labels; //导入依赖的package包/类
@GET
@Path("/latest")
public Response getLatest(@QueryParam("limit") @DefaultValue("25") final Integer limit,
                          @QueryParam("since") final Long since,
                          @QueryParam("username") final String username,
                          @Context GraphDatabaseService db) throws IOException {
    ArrayList<Map<String, Object>> results = new ArrayList<>();
    Long latest = getLatestTime(since);

    try (Transaction tx = db.beginTx()) {
        final Node user = Users.findUser(username, db);

        RecordStorageEngine recordStorageEngine = dbapi.getDependencyResolver()
                .resolveDependency(RecordStorageEngine.class);
        StoreAccess storeAccess = new StoreAccess(recordStorageEngine.testAccessNeoStores());
        Long highId = storeAccess.getRawNeoStores().getNodeStore().getHighestPossibleIdInUse();

        int counter = 0;
        while (counter < limit && highId > -1) {
            Node post;
            try {
                post = db.getNodeById(highId);
            } catch (NotFoundException e) {
                continue;
            } finally {
                highId--;
            }

            if (post.getLabels().iterator().next().name().equals(Labels.Post.name())) {
                Long time = (Long) post.getProperty("time");
                if (time < latest) {
                    counter++;
                    Map<String, Object> properties = post.getAllProperties();
                    Node author = getAuthor(post, (Long) properties.get(TIME));

                    properties.put(USERNAME, author.getProperty(USERNAME));
                    properties.put(NAME, author.getProperty(NAME));
                    properties.put(HASH, author.getProperty(HASH));
                    properties.put(LIKES, post.getDegree(RelationshipTypes.LIKES));
                    properties.put(REPOSTS, post.getDegree(Direction.INCOMING)
                            - 1 // for the Posted Relationship Type
                            - post.getDegree(RelationshipTypes.LIKES)
                            - post.getDegree(RelationshipTypes.REPLIED_TO));
                    if (user != null) {
                        properties.put(LIKED, userLikesPost(user, post));
                        properties.put(REPOSTED, userRepostedPost(user, post));
                    }
                    results.add(properties);
                }
            }
        }
    }
    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:55,代码来源:Search.java

示例13: findUser

import com.maxdemarzi.Labels; //导入依赖的package包/类
public static Node findUser(String username, @Context GraphDatabaseService db) {
    if (username == null) { return null; }
    Node user = db.findNode(Labels.User, USERNAME, username);
    if (user == null) { throw UserExceptions.userNotFound; }
    return user;
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:7,代码来源:Users.java

示例14: getTags

import com.maxdemarzi.Labels; //导入依赖的package包/类
@GET
@Path("/{hashtag}")
public Response getTags(@PathParam("hashtag") final String hashtag,
                         @QueryParam("limit") @DefaultValue("25") final Integer limit,
                         @QueryParam("since") final Long since,
                         @QueryParam("username") final String username,
                         @Context GraphDatabaseService db) throws IOException {
    ArrayList<Map<String, Object>> results = new ArrayList<>();
    LocalDateTime dateTime;
    if (since == null) {
        dateTime = LocalDateTime.now(utc);
    } else {
        dateTime = LocalDateTime.ofEpochSecond(since, 0, ZoneOffset.UTC);
    }
    Long latest = dateTime.toEpochSecond(ZoneOffset.UTC);

    try (Transaction tx = db.beginTx()) {
        Node user = null;
        if (username != null) {
            user = Users.findUser(username, db);
        }

        Node tag = db.findNode(Labels.Tag, NAME, hashtag.toLowerCase());
        if (tag != null) {
            LocalDateTime earliestTag = LocalDateTime.ofEpochSecond((Long) tag.getProperty(TIME), 0, ZoneOffset.UTC);

            int count = 0;
            while (count < limit && (dateTime.isAfter(earliestTag))) {
                RelationshipType relType = RelationshipType.withName("TAGGED_ON_" +
                        dateTime.format(dateFormatter));

                for (Relationship r1 : tag.getRelationships(Direction.INCOMING, relType)) {
                    Node post = r1.getStartNode();
                    Map<String, Object> result = post.getAllProperties();
                    Long time = (Long) result.get("time");

                    if (count < limit && time < latest) {
                        Node author = getAuthor(post, time);
                        Map userProperties = author.getAllProperties();
                        result.put(USERNAME, userProperties.get(USERNAME));
                        result.put(NAME, userProperties.get(NAME));
                        result.put(HASH, userProperties.get(HASH));
                        result.put(LIKES, post.getDegree(RelationshipTypes.LIKES));
                        result.put(REPOSTS, post.getDegree(Direction.INCOMING)
                                - 1 // for the Posted Relationship Type
                                - post.getDegree(RelationshipTypes.LIKES)
                                - post.getDegree(RelationshipTypes.REPLIED_TO));
                        if (user != null) {
                            result.put(LIKED, userLikesPost(user, post));
                            result.put(REPOSTED, userRepostedPost(user, post));
                        }
                        results.add(result);
                        count++;
                    }
                }
                dateTime = dateTime.minusDays(1);
            }
            tx.success();
            results.sort(Comparator.comparing(m -> (Long) m.get(TIME), reverseOrder()));
        } else {
            throw TagExceptions.tagNotFound;
        }
    }
    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:66,代码来源:Tags.java


注:本文中的com.maxdemarzi.Labels类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。