PlotDirector/Tools/WriterInvestigations/build_production_v01.py

114 lines
16 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Build reviewed structured evidence metadata around the verbatim, frozen editorial source."""
import json
from pathlib import Path
ROOT=Path(__file__).resolve().parents[2];D=ROOT/'Docs/Writer/Investigations'
source=json.loads((D/'Production-Editorial-Source-v0.1.json').read_text())
# ID, author-safe description, heading, practical exercise, existing capability IDs.
areas=[
('disconnected','Disconnected plot events','Some events may need stronger connections','Choose three important events. Write how each one changes the situation and makes the next event possible.',['threads','timeline']),
('causality','Weak cause and effect','Choices and consequences may need a clearer chain','For three important events, identify the decision that caused each event, what changed and what new difficulty followed.',['threads']),
('agency','Passive protagonist','Your main character may need more influence over events','Choose a turning point. Give the main character a consequential choice, then trace the new problem that choice creates.',['characters','threads']),
('direction','Unclear story direction','Your story may need a clearer direction','Write one sentence about what the main character is trying to achieve. Sketch two possible next decisions and compare their consequences.',['threads']),
('motivation','Unconvincing character motivation','Some decisions may need clearer reasons','Choose one difficult decision. List what the character wants, what they fear losing and why this choice makes sense to them now.',['characters']),
('development','Limited character development','Your characters may need more room to change','Compare a character before and after three major events. Record what each experience changes in their behaviour, outlook or relationships.',['characters']),
('relationships','Underdeveloped relationships','Relationships may need to affect more of the story','Choose two characters. Identify what each wants from the other, where those wishes conflict and one decision that changes their relationship.',['relationships']),
('slow','Slow or repetitive scenes','Some scenes may need a clearer purpose','Choose a slow scene. Note what changes between its beginning and end, then identify description or dialogue that does not contribute to that change.',['write','review']),
('rushed','Rushed events and consequences','Important events may need more room for their consequences','Choose an important event. Add a beat for immediate reaction, a decision shaped by it and a later consequence. Compare the pace before cutting anything.',['write','review']),
('conflict','Weak conflict','Obstacles may need to put more pressure on choices','Choose a goal and its main obstacle. Make progress require a difficult choice or cost, rather than resolving the obstacle immediately.',['threads','write']),
('stakes','Insufficient stakes','What is at risk may need to feel more concrete','Write what the main character could lose if they fail, why that loss matters to them and where the reader first sees that risk.',['characters','write']),
('emotion','Weak emotional impact','Emotional moments may need a stronger connection to action','Choose an emotional moment. Identify its trigger, show a specific reaction and let that feeling influence the character’s next decision.',['review','write']),
('chronology','Chronology inconsistencies','The sequence and timing of events may need checking','Place the relevant events in order. Note elapsed time and check that each consequence occurs after its cause.',['timeline']),
('whereabouts','Character whereabouts problems','Character movement may need a clearer record','For one complicated sequence, record where each character starts, how they move and when they arrive. Check that travel and overlapping actions are possible.',['timeline']),
('knowledge','Character knowledge inconsistencies','Who knows what may need a closer check','Choose one revelation. List who learns it, how and when, then check earlier scenes for decisions that depend on knowing it.',['timeline']),
('continuity','General continuity difficulties','Established details may need a more dependable record','Choose a detail that changed. Record its current version, locate later scenes that depend on it and check those scenes against the same reference.',['timeline','characters']),
('unclear','Unresolved or unclear concern','Start with one moment that does not feel right','Choose a short passage. Note where your interest, understanding or emotional connection changes, then describe what you hoped the passage would achieve.',[])]
# Evidence is deliberately sparse: absence/uncertainty is never positive confirmation.
E={
'Q02':{'A':{'disconnected':-3,'causality':-2},'B':{'disconnected':3,'causality':2},'C':{'disconnected':1,'direction':1}},
'Q03':{'A':{'agency':-3,'causality':-2,'disconnected':-1},'B':{'agency':3,'causality':1},'C':{'disconnected':3,'causality':3}},
'Q04':{'A':{'direction':-3},'B':{'direction':2},'C':{'direction':3},'D':{'direction':2}},
'Q05':{'A':{'motivation':-3},'B':{'motivation':2},'C':{'motivation':3}},
'Q06':{'A':{'development':-3},'B':{'development':2},'C':{'development':3}},
'Q07':{'A':{'relationships':-3,'agency':-1},'B':{'relationships':2},'C':{'relationships':3},'D':{'continuity':2}},
'Q08':{'A':{'slow':2},'B':{'slow':2},'C':{'rushed':2},'D':{'slow':1,'rushed':1}},
'Q09':{'A':{'slow':2},'B':{'slow':3,'conflict':1},'C':{'slow':2},'E':{'rushed':2,'slow':-2}},
'Q10':{'A':{'rushed':-3,'emotion':-1},'B':{'rushed':2,'emotion':1},'C':{'rushed':3,'emotion':2}},
'Q11':{'A':{'conflict':-3},'B':{'conflict':3},'C':{'conflict':3,'stakes':1}},
'Q12':{'A':{'stakes':-3,'conflict':-1},'B':{'stakes':2,'conflict':1},'D':{'stakes':3,'conflict':2}},
'Q13':{'A':{'emotion':-3},'B':{'emotion':3},'C':{'emotion':2,'rushed':2}},
'Q14':{'A':{'chronology':3,'continuity':1},'B':{'whereabouts':3,'continuity':1},'C':{'knowledge':3,'continuity':1},'D':{'continuity':3},'E':{'continuity':3}},
'Q15':{'A':{'continuity':-1},'B':{'continuity':2},'C':{'continuity':1},'D':{'continuity':2}},
'Q16':{'A':{'continuity':3},'B':{'continuity':3},'C':{'chronology':1,'whereabouts':1,'continuity':2},'D':{'knowledge':3,'continuity':1}},
'Q17':{'A':{'slow':1,'conflict':1,'stakes':1},'B':{'motivation':1,'emotion':1},'C':{'slow':1,'rushed':1},'D':{'causality':1},'E':{'continuity':1}},
'Q18':{'A':{'direction':1},'B':{'motivation':1},'C':{'slow':1},'D':{'emotion':1,'conflict':1},'E':{'continuity':1}},
'Q19':{'A':{'direction':1},'B':{'motivation':1},'C':{'causality':1,'slow':1},'D':{'emotion':1,'conflict':1},'E':{'continuity':1}}}
# One real question = one evidence dimension; related unsure-route items share BOTH dimension and group.
dims=['routing','event-connections','story-driver','direction','motives','development','relationships','pacing-section','scene-content','consequences','obstacles','stakes','emotion','continuity-kind','record-keeping','contradiction-cause','reported-concern','reported-concern','reported-concern']
routes={k:[f'Q{n:02}' for n in nums] for k,nums in zip('ABCDEF',[(2,3,4),(5,6,7),(8,9,10),(11,12,13),(14,15,16),(17,18,19)])}
# Follow-up links are relevance hints, not fixed next-question pointers or prerequisite journeys.
related={
'Q02':['Q03','Q04','Q11','Q14'], 'Q03':['Q02','Q05','Q07','Q11'], 'Q04':['Q03','Q05','Q12','Q18'],
'Q05':['Q06','Q07','Q03','Q13','Q17'], 'Q06':['Q05','Q07','Q10','Q13'], 'Q07':['Q05','Q06','Q03','Q15'],
'Q08':['Q09','Q10','Q11','Q13'], 'Q09':['Q08','Q10','Q11','Q02'], 'Q10':['Q08','Q09','Q06','Q13'],
'Q11':['Q12','Q13','Q03','Q09'], 'Q12':['Q11','Q13','Q04','Q05'], 'Q13':['Q11','Q12','Q05','Q10','Q17'],
'Q14':['Q15','Q16','Q02','Q07'], 'Q15':['Q14','Q16','Q07','Q17'], 'Q16':['Q14','Q15','Q02','Q10'],
'Q17':['Q18','Q19'], 'Q18':['Q17','Q19'], 'Q19':['Q17','Q18']}
follow={};questions=[]
uncertain={'Q02':['D'],'Q03':['D'],'Q05':['D'],'Q06':['D'],'Q08':['E'],'Q09':['D'],'Q10':['D'],'Q11':['D'],'Q12':['C'],'Q13':['D'],'Q16':['E'],'Q17':['F'],'Q18':['F'],'Q19':['F']}
for n,q in enumerate(source,1):
id=q['Id'];effects=E.get(id,{});hs=sorted({h for a in effects.values() for h in a}) or ['unclear'];options=[]
for a in q['Options']:
aid=a['Id'];weights=effects.get(aid,{})
options.append(dict(Id=aid,Text=a['Text'],Uncertain=aid in uncertain.get(id,[]),Contributions=[dict(Hypothesis=h,Dimension=dims[n-1],Aspect='general',Weight=w) for h,w in weights.items()]))
nxt=list(related.get(id,[]))
if id=='Q01':nxt=routes[aid]
elif id in ['Q17','Q18','Q19'] and aid in 'ABCDE':nxt=routes[aid]+nxt
# Rushing isn't a slowness problem. Knowledge and location concerns retain their continuity focus.
if id=='Q09' and aid=='E':nxt=['Q10','Q13','Q08']
if id=='Q14' and aid in 'ABC':nxt=['Q16','Q15','Q02' if aid=='A' else 'Q07']
if aid in uncertain.get(id,[]) and id not in ['Q17','Q18','Q19']:nxt=next((xs for xs in routes.values() if id in xs),[])
if weights and all(w<=0 for w in weights.values()):nxt=next((xs for xs in routes.values() if id in xs),[])
follow[id+'.'+aid]=dict(Questions=[x for x in dict.fromkeys(nxt) if x!=id],Limitation='A self-report, not manuscript evidence. '+('Uncertain/unfinished development: no positive contribution.' if aid in uncertain.get(id,[]) else 'A symptom can have several explanations; weights are not probabilities.'))
questions.append(dict(Id=id,Text=q['Text'],Help=q.get('Help',''),Purpose='ActionPreference' if id=='Q01' else 'Discrimination' if n>=17 else 'Discovery',Group='uncertain-route-signals' if n>=17 else id.lower(),InformationValue=2,Hypotheses=hs,Dimensions=[dims[n-1]],Options=options))
# Challenges are declared only where a real answer challenges the named hypothesis.
challenges={h:sorted(q['Id'] for q in questions if any(v['Hypothesis']==h and v['Weight']<0 for o in q['Options'] for v in o['Contributions'])) for h,*_ in areas}
caps=json.loads((D/'synthetic-catalogue-v2.json').read_text())['Capabilities']
for c in caps:
c['Description']={'characters':'Record and review character details, motivations and development.','write':'Compare chapter and scene intentions and develop a scene with a clear change.','threads':'Lay out plot lines, threads and the scene events that develop them.','timeline':'Inspect the order of scenes and their recorded story context.','relationships':'Review and develop recorded relationships between characters.'}[c['Id']]
caps.append(dict(Id='review',Name='Review your writing',Description='Read the canonical manuscript and record anchored observations or revision decisions.',Resolver='Review',ActionText='Open Review',Available=True,RequiresBook=True,RequiresProject=True,Context='book',Authority='ProjectAccess'))
hypotheses=[];templates=[]
for h,description,title,action,mapped in areas:
hd=sorted({v['Dimension'] for q in questions for o in q['Options'] for v in o['Contributions'] if v['Hypothesis']==h})
hd=hd or ['reported-concern']
hypotheses.append(dict(Id=h,Description=description,Summary=title,Reason='Your answers suggest this is an area worth examining.',Uncertainty='This is based on your answers, not an analysis of your manuscript.',Dimensions=hd,Capabilities=mapped,MinDimensions=2,MinGroups=2,Threshold=4))
templates.append(dict(Hypothesis=h,Title=title,Explanation='Your answers point towards '+description.lower()+'. The observations below show what informed that suggestion.',Action=action,Qualification='This is based on your answers, not an analysis of your manuscript. Other explanations may fit.'))
# Only a single direct item is supplied for some areas: never invent independent evidence to qualify them.
tentative=[h['Id'] for h in hypotheses if len({v['Dimension'] for q in questions for o in q['Options'] for v in o['Contributions'] if v['Hypothesis']==h['Id'] and v['Weight']>0})<2 or not challenges[h['Id']]]
catalogue=dict(SchemaVersion=2,EngineVersion=3,Version='guided-investigation-production-v0.1',Synthetic=False,MinAnswers=8,MaxAnswers=12,Dimensions=sorted(set(dims)),Concerns=[dict(Id=a['Id'],Text=a['Text'],Priors={h:1 for q in questions if q['Id'] in routes[a['Id']] for h in q['Hypotheses']}) for a in source[0]['Options']],Hypotheses=hypotheses,Questions=questions,Capabilities=caps,Editorial=dict(Version='results-v0.1',OpeningQuestion='Q01',Routes=routes,FollowUps=follow,Challenges=challenges,TentativeOnly=tentative,Results=templates))
for result in templates:
result['States']=['healthy','uncertain'] if result['Hypothesis']=='unclear' else ['tentative','ambiguous','conflicting']+([] if result['Hypothesis'] in tentative else ['supported','unavailable'])
state_text={
'supported':('A useful next step','Your answers support the following next step. The observations below explain why it may help.'),
'unavailable':('A relevant tool is not available right now','Your answers suggest a useful direction, but its PlotDirector tool cannot be offered right now. You can still try the writing action below.'),
'conflicting':('Some answers need a closer look','Some answers point in different directions. They may describe different moments, or your understanding may have changed. Revisit the answers below before treating either possibility as settled.'),
'ambiguous':('There is more than one way to understand these answers','Different interpretations fit parts of your answers, which may describe different moments or aspects of the story. Try one of the actions below and compare what you learn before choosing a tool.'),
'tentative':('One possibility may be worth exploring','This is a plausible direction, rather than a confirmed finding. These questions leave some of it uncertain; try the action below and see whether it fits your experience.'),
'healthy':('Your answers do not point to a clear writing problem','The elements you described as working well do not justify inventing a problem. You can build on those strengths while checking the moment that first concerned you.'),
'uncertain':("Let's start with one moment in your story",'You do not need to name the problem yet. The answers so far do not justify choosing an explanation or a tool. A small, concrete reading exercise may help you find a starting point.')}
catalogue['Editorial']['States']={kind:dict(Title=title,Explanation=explanation,Action='Choose a scene you feel works well. Identify the choice, change or emotional beat that makes it effective, then compare it with the passage that concerned you.' if kind=='healthy' else templates[-1]['Action'],Qualification='These suggestions are based on your questionnaire answers, not an analysis of your manuscript.') for kind,(title,explanation) in state_text.items()}
caveats={
'Q02.C':'Not knowing the arrangement is weak evidence only; it does not establish that events are disconnected.',
'Q02.D':'An unfinished event sequence is not proof of a writing defect.',
'Q06.B':'Some characters may intentionally remain unchanged. This does not mean every character needs an arc.',
'Q07.B':'Emotionally important relationships need not always drive plot; this is a possibility to examine, not a rule.',
'Q09.A':'Description is not inherently slow; this answer concerns scenes the author already experiences as slow.',
'Q14.E':'Several does not mean all: only general continuity receives support, not every specific subtype.',
'Q15.A':'Maintained records weakly challenge organisational difficulty; they do not prove that story details are consistent.',
'Q15.C':'Relying on memory is context, not proof of errors; it contributes only weak support.',
'Q16.C':'Timing OR location is ambiguous: each specific subtype receives only weak support; general continuity receives moderate support.',
'Q17.A':'Loss of interest has many possible causes; each contribution is weak and shares the preference-probe group.',
'Q19.C':'Flow can concern pace or connections; both contributions are weak and do not establish a diagnosis.'}
for key,note in caveats.items():follow[key]['Limitation']+=' '+note
(D/'production-catalogue-v0.1.json').write_text(json.dumps(catalogue,ensure_ascii=False,indent=2)+'\n')
print('Built',len(questions),'questions',sum(len(q['Options']) for q in questions),'answers;',len(areas),'areas; tentative-only:',tentative)