Package org.wymiwyg.knobot.relations

Examples of org.wymiwyg.knobot.relations.Relation


        subject);
    int effectiveTill = till;
    for (int i = (from - 1); i <= effectiveTill; i++) {
      try {
        // Relation relation = itemsList.getRelation(i);
        Relation relation = itemIterator.nextRelation();
        if ((!unOrdered) && (relation.getStrength() < minimalRelevance)) {
          break;
        }
        Resource targetResource = relation.getTarget();
        if (!isPermitted(targetResource)) {
          effectiveTill++;
          continue;
        }
        if (hideRead
            && targetResource.hasProperty(KNOBOT.isReadBy, subject)) {
          effectiveTill++;
          continue;
        }
        if (relation.isPath()) {
          effectiveTill++;
        }
        if (log.isDebugEnabled()) {
          log.debug("returning " + i + "nd relation with strenght"
              + relation.getCurrentStrength() + "(" + relation
              + ")");
        }

        boolean isItem = targetResource.hasProperty(RDF.type, RSS.item);
        if (isItem && !hasAcceptedLanguage(targetResource, ehRequest)) {
          effectiveTill++;
          continue;
        }
        Model itemModel = getEventInRangeAndArea(targetResource,
            startDate, endDate, area, relevantMonths, relevantAreas);
        if (itemModel == null) {
          continue;
        }
        /*
         * relation = itemsList.getRelation(i); log.info( "returning " +
         * i + "nd relation with strenght"
         */
        // resultModel.write(System.out);
        Model relationModel = JenaUtil.getExpandedResource(relation
            .getResource(), 3, true);
        Statement feedStmt = relation.getTarget().getProperty(
            AGGREGATOR.feed);
        if (feedStmt != null) {
          relationModel.add(feedStmt);
        }
        // relationModel.write(System.out);
        /*
         * Resource relationInResourceModel = (Resource) relation
         */
        Resource relationInResourceModel = JenaUtil
            .getRoots(relationModel)[0];
        relationInResourceModel.removeAll(KNOBOT.nextRelation);
        // we may still have nextRelation stmts in relationModel
        resultModel.add(JenaUtil.getExpandedResource(
            relationInResourceModel, 3, true));

        resultModel.add(itemModel);

        Resource item = (Resource) targetResource.inModel(resultModel);
        addMissingSummaries(item);
        addCommentCount(item);

        /*
         * Util.getExpandedResource(relation.getTarget(),
         */
        ResIterator aggregatorIter = model.listSubjectsWithProperty(
            AGGREGATOR.aggregated, relation.getTarget());
        if (aggregatorIter.hasNext()) {
          resultModel.add(JenaUtil.getExpandedResource(aggregatorIter
              .nextResource(), 2, true));
        }

View Full Code Here


   */
  private void process(ResIterator iter) {
    while (iter.hasNext()) {
      Resource currentRelationRes = iter.nextResource();
      try {
        Relation relation = new ConcreteRelation(currentRelationRes);
        Resource target = relation.getTarget();
        if (target.hasProperty(RDF.type, RSS.item) || target.isAnon()) {
            currentRelationRes.addProperty(RDF.type, KNOBOT.InlineRelation);
        }
      } catch (Exception ex) {
        log.info("Exception on "+currentRelationRes+" "+ex+"!");
View Full Code Here

        /*
         * itemIterator = new StrengthSortedRelationIterator(
         * (CSRelationIterator) itemIterator);
         */
        while (itemIterator.hasNext()) {
            Relation current = itemIterator.nextRelation();
            if (current.getStrength() < minimalRelevance) {
              continue;
            }
            Resource relationResource = current.getResource();
            Model relationModel = JenaUtil.getExpandedResource(
                    relationResource, 3);
            relationResource = (Resource) relationResource
                    .inModel(relationModel);
            relationResource.removeAll(KNOBOT.nextRelation);
            resultModel.add(JenaUtil.getExpandedResource(relationResource, 3));
            Resource target = current.getTarget();
            Model targetModel = getItemModelWithoutComments(target, acceptLanguagesStringList, 0, minimalRelevance);/*= JenaUtil
            .getExpandedResource(target, 3);*/
            target = (Resource) target.inModel(targetModel);
            target.removeAll(KNOBOT.firstRelation);
            resultModel.add( JenaUtil
                    .getExpandedResource(target, 3));
            if (recursion < MAX_COMMENT_RECURSION) {
                addComments(current.getTarget(), resultModel, acceptLanguagesStringList, recursion + 1, minimalRelevance);
            }
        }
    }
View Full Code Here

                new InverseIndirectRelationIterator(
                        new InverseDirectRelationIterator(resource),
                        minimalRelevance));
        try {
            for (int i = 0; i < till; i++) {
                Relation current = iter.nextRelation();
                if (current.getStrength() < minimalRelevance) {
                    break;
                }
                resultModel.add(JenaUtil.getExpandedResource(current
                        .getResource(), 3));
                StmtIterator titleStmts = current.getSource().listProperties(
                        RSS.title);
                while (titleStmts.hasNext()) {
                    resultModel.add(titleStmts.nextStatement());
                }
                resultList.add(current.getSource());
            }
        } catch (NoSuchElementException ex) {
        }
        if (log.isDebugEnabled()) {
            log.debug("will return " + resultList.size() + " containers");
View Full Code Here

        subject);
    int effectiveTill = requestParameters.getTill() - 1;
    for (int i = 0; i <= effectiveTill; i++) {
      try {
        // Relation relation = itemsList.getRelation(i);
        Relation relation = itemIterator.nextRelation();

        if ((!requestParameters.getUnOrdered())
            && (relation.getCurrentStrength() < requestParameters
                .getMinimalRelevance())) {
          break;
        }
        Resource targetResource = relation.getTarget();
        if (!isRelationToBeShown(relation, targetResource, hideRead,
            subject, ehRequest, requestParameters)) {
          effectiveTill++;
          continue;
        }
       
        if (relation.isPath()) {
          effectiveTill++;
        }
        if (log.isDebugEnabled()) {
          log.debug("returning " + i + "nd relation with strenght"
              + relation.getCurrentStrength() + "(" + relation
              + ")");
          log.debug("target: "+targetResource);
        }
        boolean isItem = targetResource.hasProperty(RDF.type, RSS.item);
        if (i < (requestParameters.getFrom() - 1)) {
          continue;
        }
        /*
         * relation = itemsList.getRelation(i); log.info( "returning " +
         * i + "nd relation with strenght"
         */
        // resultModel.write(System.out);
        Model relationModel = JenaUtil.getExpandedResource(relation
            .getResource(), 3, true);
        Statement feedStmt = relation.getTarget().getProperty(
            AGGREGATOR.feed);
        if (feedStmt != null) {
          relationModel.add(feedStmt);
        }
        // relationModel.write(System.out);
        /*
         * Resource relationInResourceModel = (Resource) relation
         */
        Resource relationInResourceModel = JenaUtil
            .getRoots(relationModel)[0];
        relationInResourceModel.removeAll(KNOBOT.nextRelation);
        // we may still have nextRelation stmts in relationModel
        resultModel.add(JenaUtil.getExpandedResource(
            relationInResourceModel, 3, true));

        boolean isAgent = targetResource.hasProperty(RDF.type,
            FOAF.Agent);

        Model targetModel = JenaUtil.getExpandedResource(
            targetResource, 3, true);
        Resource target = targetResource;
        targetResource = (Resource) targetResource.inModel(targetModel);
        targetResource.removeAll(KNOBOT.firstRelation);
        resultModel
            .add(JenaUtil.getExpandedResource(targetResource, 3));
        if (isItem) {
          Resource item = (Resource) target.inModel(resultModel);
          addMissingSummaries(item);
          addCommentCount(item);
          // itemSeq.add(item);
        }

        /*
         * Util.getExpandedResource(relation.getTarget(),
         */
        ResIterator aggregatorIter = model.listSubjectsWithProperty(
            AGGREGATOR.aggregated, relation.getTarget());
        if (aggregatorIter.hasNext()) {
          resultModel.add(JenaUtil.getExpandedResource(aggregatorIter
              .nextResource(), 2, true));
        }
        if (isAgent) {
          if (target.hasProperty(RDF.type, ROLE.Participation)) {
            resultModel.add(JenaUtil.getExpandedResource(target
                .getProperty(ROLE.group).getResource(), 2));
            resultModel.add(JenaUtil
                .getExpandedResource(target.getProperty(
                    ROLE.participant).getResource(), 2));
          }
        }
        // fdr the atom transformation
        if (!target.hasProperty(DC.date)) {
          target.addProperty(DC.date, Util.formatDate(new Date()));
        }

      } catch (NoSuchElementException ex) {
        log.debug("No such element at position " + i, ex);
        break;
      }
    }
    boolean hasMore = itemIterator.hasNext();

    if (hasMore && !requestParameters.getUnOrdered()) {
      Relation relation = itemIterator.nextRelation();
      hasMore = !(relation.getCurrentStrength() < requestParameters
          .getMinimalRelevance());
    }
    RelationNodeUtil.addInverseRelations(resource, resultModel,
        requestParameters.getMinimalRelevance());
    resource = (Resource) resource.inModel(resultModel);
View Full Code Here

  private void process(ResIterator iter, boolean delete, PrintWriter out) {
    Collection removing = new ArrayList();
    while (iter.hasNext()) {
      Resource currentRelationRes = iter.nextResource();
      try {
        Relation relation = new ConcreteRelation(currentRelationRes);
        relation.getChildStrength();
        relation.getChildStrengthReduction();
        relation.getCurrentChildStrength();
        relation.getComparativeStrength();
        Resource target = relation.getTarget();
        if (target.isAnon()) {
          //TODO this is wrong (agents are anon!), look more detail at osar problem
          if (!target.hasProperty(RDF.type, FOAF.Agent)) {
            throw new RuntimeException("target is anon and not an Agent");
          }
        }
        relation.getTargetLabel();
        relation.getEffectiveDate();
      } catch (Exception ex) {
        log.info("Exception on "+currentRelationRes+" "+ex+", will remove");
        removing.add(currentRelationRes);
      }
    }
View Full Code Here

              minimalRelevance));
      //TopicsList topicsList = new TopicsList(resource, 0);
      List result = new ArrayList();
      try {
        for (int i = 0; i < 5; i++) {
          Relation relation = iter.nextRelation();//topicsList.getRelation(i);
          resultModel.add(JenaUtil.getExpandedResource(relation
              .getResource(), 2));
          Resource source = relation.getSource();
          if (source.hasProperty(RSS.title)) {
              StmtIterator titles =  source.listProperties(RSS.title);
              while (titles.hasNext()) {
                  resultModel.add(titles.nextStatement());
              }
          }
          if (relation.getStrength() < minimalRelevance) {
            break;
          }
          result.add(relation);
        }
      } catch (NoSuchElementException ex) {
View Full Code Here

  private void antiggregate(Resource resource, Model removedModel,
      float resourceThreshold, float otherThreshold) {
    RelationIterator iter = new DirectRelationIterator(resource);
    int pos = 0;
    OUTER: while (iter.hasNext()) {
      Relation current = iter.nextRelation();
      if (++pos > 20) {
        //if (current.getCurrentComparativeStrength() <
        // resourceThreshold) {
        Resource target = current.getTarget();
        if (target == null) {
          log.warn("target is null");
          continue;
        }
        RelationIterator inverseIter = new InverseDirectRelationIterator(
            target);
        while (inverseIter.hasNext()) {
          Relation currentInverse = inverseIter.nextRelation();
          if (/*
             * (current.getComparativeStrength() >
             * resourceThreshold) ||
             */(!currentInverse.getSource().equals(resource) && (current
              .getCurrentComparativeStrength() > otherThreshold))) {
            continue OUTER;
          }
        }
        removeByTarget(target, removedModel);
View Full Code Here

   * @param removedModel
   */
  private void removeRelationsToTarget(Resource target, Model removedModel) {
    RelationIterator inverseIter = new InverseDirectRelationIterator(target);
    while (inverseIter.hasNext()) {
      Relation currentInverse = inverseIter.nextRelation();
      Resource relationResource = ((ConcreteRelation) currentInverse)
          .getRealResource();
      try {
        RelationManager.removeRelation(relationResource);
      } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of org.wymiwyg.knobot.relations.Relation

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.